func NewSocketClusterClient(host string, profileName string, authToken string, userAgent string, secure bool, dbPath string) error { authDetails := socketcluster.AuthDetails{ Host: host, ProfileName: profileName, AuthToken: authToken, UserAgent: userAgent, SecureWS: secure, } sc, err = socketcluster.NewClient(authDetails, dbPath) if err != nil { return err } sc.OnAuthSuccess = func() { } sc.OnAuthFailure = func(err string) { } sc.OnData = func(event *socketcluster.Event) { data, err := json.Marshal(event) if err == nil { sc.DB.PutBytes("data", data) } } return nil }
func main() { authDetails := socketcluster.AuthDetails{ Host: "localhost:8000", ProfileName: "", AuthToken: "", UserAgent: "", SecureWS: false, } dbPath := "./" sc, err := socketcluster.NewClient(authDetails, dbPath) if err != nil { fmt.Printf("%v", err) return } // OnAuthSuccess sc.OnAuthSuccess = func() { // Auth has been successful. } sc.OnAuthFailure = func(err string) { // Do something } // OnData sc.OnData = func(event *socketcluster.Event) { if event.Data != nil { // println("Data for id: ", event.Rid) } } for { } }