novuhq / go-novu

GO SDK for Novu - The open-source notification infrastructure for engineers. 🚀
MIT License
58 stars 44 forks source link

Improve Documentation Examples #39

Closed king-11 closed 1 year ago

king-11 commented 1 year ago

Code examples in the go quickstart directly use main function for all the create/update/trigger workflows.

package main

import (
 "context"
 "fmt"
 "log"

 novu "github.com/novuhq/go-novu/lib"
)

# Create a subscriber
func main() {
    ctx := context.Background()
    subscriberID := "<REPLACE_WITH_YOUR_SUBSCRIBER>"
    subscriber := novu.SubscriberPayload{
     LastName: "Skjæveland",
     Email:    "benedicte.skjaeveland@example.com",
     Avatar:   "https://randomuser.me/api/portraits/thumb/women/79.jpg",
     Data: map[string]interface{}{
      "location": map[string]interface{}{
       "city":     "Ballangen",
       "state":    "Aust-Agder",
       "country":  "Norway",
       "postcode": "7481",
      },
     },
    }

 resp, err := novuClient.SubscriberApi.Identify(ctx, subscriberID, subscriber)
 if err != nil {
  log.Fatal("Subscriber error: ", err.Error())
  return
 }

 fmt.Println(resp)
}

It is probably better to make them modular as separate functions instead of main which are callable by other functions, for example the kotlin quickstart uses that form of modularization.

suspend fun updateSubscriber(): ResponseWrapper<SubscriberResponse>? {
        val novu = Novu(apiKey = "API_KEY")
        val subscriberRequest = UpdateSubscriberRequest(
            email = "validemail@sample.com",
            firstName = "John",//optional
            lastName = "Doe",//optional
            phone = "123456789",//optional
            avatar = "sample-avatar"//optional
        )
        val subscriberId = "12345"
        return CoroutineScope(Dispatchers.IO).async {
            novu.updateSubscriber(subscriberId, subscriberRequest)
        }.await()
    }
king-11 commented 1 year ago

@sumitsaurabh927 is this something I should work on?

unicodeveloper commented 1 year ago

No, Please work on other issues. It's fine for the quickstart to call the main function. Both of those approaches work either ways.

king-11 commented 1 year ago

sure got it @unicodeveloper the idea was that if we have modular functions user can directly copy and plug them into their code