// SaveApplication will create a application if the ID field is not initialized // if ID field is initialized, it will update the conresponding application. func (r *Registry) SaveApplication(app *models.Application, reply *models.Application) error { db, err := getDB() if err != nil { return err } err = db.Save(app).Error if err != nil { return err } key, err := r.keygen.GenRandomKey(int64(app.ID)) if err != nil { return err } app.AppKey = key err = db.Save(app).Error if err != nil { return err } reply.ID = app.ID reply.AppName = app.AppName reply.AppDescription = app.AppDescription reply.AppKey = app.AppKey reply.ReportUrl = app.ReportUrl reply.AppToken = app.AppToken reply.AppDomain = app.AppDomain reply.CreatedAt = app.CreatedAt reply.UpdatedAt = app.UpdatedAt return nil }
func setApplication(target *models.Application, src *models.Application) { target.ID = src.ID target.AppName = src.AppName target.AppDescription = src.AppDescription target.AppKey = src.AppKey target.ReportUrl = src.ReportUrl target.AppToken = src.AppToken target.AppDomain = src.AppDomain target.CreatedAt = src.CreatedAt target.UpdatedAt = src.UpdatedAt }
func addApplication() error { args := models.Application{} reader := bufio.NewReader(os.Stdin) fmt.Printf("application name: ") name, err := reader.ReadString('\n') if err != nil { return err } args.AppName = strings.Replace(name, "\n", "", -1) fmt.Printf("application description: ") desc, err := reader.ReadString('\n') if err != nil { return err } args.AppDescription = strings.Replace(desc, "\n", "", -1) fmt.Printf("application domain: ") domain, err := reader.ReadString('\n') if err != nil { return err } args.AppDomain = strings.Replace(domain, "\n", "", -1) fmt.Printf("application report url: ") url, err := reader.ReadString('\n') if err != nil { return err } args.ReportUrl = strings.Replace(url, "\n", "", -1) fmt.Printf("application token: ") token, err := reader.ReadString('\n') if err != nil { return err } args.AppToken = strings.Replace(token, "\n", "", -1) reply := &models.Application{} err = server.RPCCallByName("registry", "Registry.SaveApplication", &args, reply) if err != nil { return err } fmt.Println("=======> application created successfully:") printStruct(reply) fmt.Println("=======") return nil }