func prepareRoutes(router *gin.Engine) { // Web Resources router.Static("/static", "web/dist") // API Routes api := router.Group("/api/v1") admin := api.Group("/admin") public := api.Group("/public") registered := api.Group("/") sameRegisteredUser := api.Group("/user") prepareMiddleware(admin, public, registered, sameRegisteredUser) admin.GET("/users", listUsers) admin.GET("/places", listPlaces) admin.POST("/places", createPlace) admin.POST("/events", createEvent) admin.PUT("/place/:placeId", updatePlace) admin.PUT("/event/:eventId", updateEvent) admin.DELETE("/event/:eventId", cancelEvent) sameRegisteredUser.GET("/:userId", getUser) sameRegisteredUser.PUT("/:userId", updateUser) sameRegisteredUser.DELETE("/:userId", disableUser) registered.POST("/buy/:seatId", buyTicket) public.GET("/place/:placeId", getPlace) public.GET("/events", listEvents) public.GET("/event/:eventId", getEvent) public.POST("/users", createUser) // TODO Checar, me huele raro...... public.POST("/login", loginUser) }
func PostLike(db gorm.DB, router *gin.Engine) { // POST /like // POST new like to database router.POST("/like", func(c *gin.Context) { var likeData model.LikeData if err := c.BindJSON(&likeData); err == nil { like := &model.Like{ LikeData: likeData, } var x_user uint64 if resp := c.Request.Header.Get(userHeader); resp != "" { conv_user, _ := strconv.ParseUint(resp, 10, 64) x_user = conv_user like.Trace.CreatedBy = x_user like.Trace.UpdatedBy = x_user if err := checkDataLike(like.LikeData); err { if err := db.Create(&like).Error; err != nil { c.AbortWithError(http.StatusBadRequest, err) } else { c.JSON(http.StatusCreated, like) } } else { c.AbortWithStatus(http.StatusBadRequest) } } else { c.AbortWithStatus(http.StatusForbidden) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
//setTemplate loads templates from rice box "views" func setTemplate(router *gin.Engine) { box := rice.MustFindBox("views") tmpl := template.New("").Funcs(template.FuncMap{ "isActive": helpers.IsActive, "stringInSlice": helpers.StringInSlice, "dateTime": helpers.DateTime, "recentPosts": helpers.RecentPosts, "tags": helpers.Tags, "archives": helpers.Archives, }) fn := func(path string, f os.FileInfo, err error) error { if f.IsDir() != true && strings.HasSuffix(f.Name(), ".html") { var err error tmpl, err = tmpl.Parse(box.MustString(path)) if err != nil { return err } } return nil } err := box.Walk("", fn) if err != nil { panic(err) } router.SetHTMLTemplate(tmpl) }
func PutGroupAdmin(db gorm.DB, router *gin.Engine) { // PUT /group_admin // Update group_admin data by id router.PUT("/group_admin/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var group_adminData model.GroupAdminData if err := c.BindJSON(&group_adminData); err == nil { group_admin := &model.GroupAdmin{ GroupAdminData: group_adminData, GroupAdminId: model.GroupAdminId{Id: id}, } if err := checkDataGroupAdmin(group_admin.GroupAdminData); err { checkGroupAdmin := &model.GroupAdmin{ GroupAdminData: group_adminData, GroupAdminId: model.GroupAdminId{Id: id}, } if err := db.First(checkGroupAdmin).Error; err == nil { db.Save(&group_admin) c.JSON(http.StatusOK, group_admin) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func PutWallEntry(db gorm.DB, router *gin.Engine) { // PUT /wall_entry // Update wall_entry data by id router.PUT("/wall_entry/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var wall_entryData model.WallEntryData if err := c.BindJSON(&wall_entryData); err == nil { wall_entry := &model.WallEntry{ WallEntryData: wall_entryData, WallEntryId: model.WallEntryId{Id: id}, } if err := checkDataWallEntry(wall_entry.WallEntryData); err { checkWallEntry := &model.WallEntry{ WallEntryData: wall_entryData, WallEntryId: model.WallEntryId{Id: id}, } if err := db.First(checkWallEntry).Error; err == nil { db.Save(&wall_entry) c.JSON(http.StatusOK, wall_entry) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func AddRepoRoutes(s *store.Engine, r *gin.Engine) { r.GET("/users/:username/repos", func(c *gin.Context) { var repos []*Repo for _, repo := range s.State.Repos { if repo.RepoOwner.Username == c.Param("username") { repos = append(repos, repo) } } c.JSON(http.StatusOK, repos) }) r.GET("/users/:username/repos/:reponame", func(c *gin.Context) { var repo *Repo for _, rp := range s.State.Repos { if rp.RepoOwner.Username == c.Param("username") && rp.Name == c.Param("reponame") { repo = rp break } } c.JSON(http.StatusOK, repo) }) }
func PutActivity(db gorm.DB, router *gin.Engine) { // PUT /activity // Update activity data by id router.PUT("/activity/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var activityData model.ActivityData if err := c.BindJSON(&activityData); err == nil { activity := &model.Activity{ ActivityData: activityData, ActivityId: model.ActivityId{Id: id}, } if err := checkDataActivity(activity.ActivityData); err { checkActivity := &model.Activity{ ActivityData: activityData, ActivityId: model.ActivityId{Id: id}, } if err := db.First(checkActivity).Error; err == nil { db.Save(&activity) c.JSON(http.StatusOK, activity) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func PutModuleEnabled(db gorm.DB, router *gin.Engine) { // PUT /module_enabled // Update module_enabled data by id router.PUT("/module_enabled/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var module_enabledData model.ModuleEnabledData if err := c.BindJSON(&module_enabledData); err == nil { module_enabled := &model.ModuleEnabled{ ModuleEnabledData: module_enabledData, ModuleEnabledId: model.ModuleEnabledId{Id: id}, } if err := checkDataModuleEnabled(module_enabled.ModuleEnabledData); err { checkModuleEnabled := &model.ModuleEnabled{ ModuleEnabledData: module_enabledData, ModuleEnabledId: model.ModuleEnabledId{Id: id}, } if err := db.First(checkModuleEnabled).Error; err == nil { db.Save(&module_enabled) c.JSON(http.StatusOK, module_enabled) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func NewUserResource(e *gin.Engine) { u := UserResource{} // Setup Routes e.GET("/users", u.getAllUsers) e.GET("/users/:id", u.getUserByID) }
func PutProfileFieldCategory(db gorm.DB, router *gin.Engine) { // PUT /profile_field_category // Update profile_field_category data by id router.PUT("/profile_field_category/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var profile_field_categoryData model.ProfileFieldCategoryData if err := c.BindJSON(&profile_field_categoryData); err == nil { profile_field_category := &model.ProfileFieldCategory{ ProfileFieldCategoryData: profile_field_categoryData, ProfileFieldCategoryId: model.ProfileFieldCategoryId{Id: id}, } if err := checkDataProfileFieldCategory(profile_field_category.ProfileFieldCategoryData); err { checkProfileFieldCategory := &model.ProfileFieldCategory{ ProfileFieldCategoryData: profile_field_categoryData, ProfileFieldCategoryId: model.ProfileFieldCategoryId{Id: id}, } if err := db.First(checkProfileFieldCategory).Error; err == nil { db.Save(&profile_field_category) c.JSON(http.StatusOK, profile_field_category) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
// setupMiddleware is an internal method where we setup GIN middleware func setupMiddleware(r *gin.Engine) { // TODO: CACHE_URL should come from an environment variable but this requires // validating and parsing of the connection url into it's base components. store, err := sessions.NewRedisStore(10, "tcp", "localhost:6379", "", []byte(config.Config.Session_Secret)) if err != nil { log.Fatalln("Failed to connect to Redis.", err) } r.Use( secure.Secure(secure.Options{ // TODO: we should get these from config AllowedHosts: []string{}, SSLRedirect: false, SSLHost: "", SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"}, STSSeconds: 315360000, STSIncludeSubdomains: true, FrameDeny: true, ContentTypeNosniff: true, BrowserXssFilter: true, ContentSecurityPolicy: "default-src 'self'", }), sessions.Sessions("session", store), auth.UserMiddleware(), ) }
func PostProfileFieldCategory(db gorm.DB, router *gin.Engine) { // POST /profile_field_category // POST new profile_field_category to database router.POST("/profile_field_category", func(c *gin.Context) { var profile_field_categoryData model.ProfileFieldCategoryData if err := c.BindJSON(&profile_field_categoryData); err == nil { profile_field_category := &model.ProfileFieldCategory{ ProfileFieldCategoryData: profile_field_categoryData, } var x_user uint64 if resp := c.Request.Header.Get(userHeader); resp != "" { conv_user, _ := strconv.ParseUint(resp, 10, 64) x_user = conv_user profile_field_category.Trace.CreatedBy = x_user profile_field_category.Trace.UpdatedBy = x_user if err := checkDataProfileFieldCategory(profile_field_category.ProfileFieldCategoryData); err { if err := db.Create(&profile_field_category).Error; err != nil { c.AbortWithError(http.StatusBadRequest, err) } else { c.JSON(http.StatusCreated, profile_field_category) } } else { c.AbortWithStatus(http.StatusBadRequest) } } else { c.AbortWithStatus(http.StatusForbidden) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func PutUrlOembed(db gorm.DB, router *gin.Engine) { // PUT /url_oembed // Update url_oembed data by id router.PUT("/url_oembed/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var url_oembedData model.UrlOembedData if err := c.BindJSON(&url_oembedData); err == nil { url_oembed := &model.UrlOembed{ UrlOembedData: url_oembedData, UrlOembedId: model.UrlOembedId{Id: id}, } if err := checkDataUrlOembed(url_oembed.UrlOembedData); err { checkUrlOembed := &model.UrlOembed{ UrlOembedData: url_oembedData, UrlOembedId: model.UrlOembedId{Id: id}, } if err := db.First(checkUrlOembed).Error; err == nil { db.Save(&url_oembed) c.JSON(http.StatusOK, url_oembed) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
// InitRoutesTopics initialized routes for Topics Controller func InitRoutesTopics(router *gin.Engine) { topicsCtrl := &controllers.TopicsController{} g := router.Group("/") g.Use(CheckPassword()) { g.GET("/topics", topicsCtrl.List) g.POST("/topic", topicsCtrl.Create) g.DELETE("/topic/*topic", topicsCtrl.Delete) g.GET("/topic/*topic", topicsCtrl.OneTopic) g.PUT("/topic/add/parameter", topicsCtrl.AddParameter) g.PUT("/topic/remove/parameter", topicsCtrl.RemoveParameter) g.PUT("/topic/add/rouser", topicsCtrl.AddRoUser) g.PUT("/topic/remove/rouser", topicsCtrl.RemoveRoUser) g.PUT("/topic/add/rwuser", topicsCtrl.AddRwUser) g.PUT("/topic/remove/rwuser", topicsCtrl.RemoveRwUser) g.PUT("/topic/add/adminuser", topicsCtrl.AddAdminUser) g.PUT("/topic/remove/adminuser", topicsCtrl.RemoveAdminUser) g.PUT("/topic/add/rogroup", topicsCtrl.AddRoGroup) g.PUT("/topic/remove/rogroup", topicsCtrl.RemoveRoGroup) g.PUT("/topic/add/rwgroup", topicsCtrl.AddRwGroup) g.PUT("/topic/remove/rwgroup", topicsCtrl.RemoveRwGroup) g.PUT("/topic/add/admingroup", topicsCtrl.AddAdminGroup) g.PUT("/topic/remove/admingroup", topicsCtrl.RemoveAdminGroup) g.PUT("/topic/param", topicsCtrl.SetParam) } }
func PostNotification(db gorm.DB, router *gin.Engine) { // POST /notification // POST new notification to database router.POST("/notification", func(c *gin.Context) { var notificationData model.NotificationData if err := c.BindJSON(¬ificationData); err == nil { notification := &model.Notification{ NotificationData: notificationData, } var x_user uint64 if resp := c.Request.Header.Get(userHeader); resp != "" { conv_user, _ := strconv.ParseUint(resp, 10, 64) x_user = conv_user notification.Trace.CreatedBy = x_user notification.Trace.UpdatedBy = x_user if err := checkDataNotification(notification.NotificationData); err { if err := db.Create(¬ification).Error; err != nil { c.AbortWithError(http.StatusBadRequest, err) } else { c.JSON(http.StatusCreated, notification) } } else { c.AbortWithStatus(http.StatusBadRequest) } } else { c.AbortWithStatus(http.StatusForbidden) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func Init(router *gin.Engine, DB *db.Session, fn func() gin.HandlerFunc) { // Simple group: v1 api := &API{DB} v1 := router.Group("/v1") { v1.Use(fn()) policies := v1.Group("policies") { policies.POST("/", api.createPolicy) policies.GET("/", api.getPolicies) policies.DELETE("/", api.deletePolicies) policies.DELETE("/:id", api.deletePolicy) policies.PUT("/:id", api.updatePolicy) } res := v1.Group("resources") { res.POST("/", api.createResource) res.GET("/:type", api.getResources) //res.GET("/:type/:id", api.getResources) res.DELETE("/", api.deleteResources) res.DELETE("/:id", api.deleteResource) res.PUT("/:id", api.updateResource) } } }
func PutNotification(db gorm.DB, router *gin.Engine) { // PUT /notification // Update notification data by id router.PUT("/notification/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var notificationData model.NotificationData if err := c.BindJSON(¬ificationData); err == nil { notification := &model.Notification{ NotificationData: notificationData, NotificationId: model.NotificationId{Id: id}, } if err := checkDataNotification(notification.NotificationData); err { checkNotification := &model.Notification{ NotificationData: notificationData, NotificationId: model.NotificationId{Id: id}, } if err := db.First(checkNotification).Error; err == nil { db.Save(¬ification) c.JSON(http.StatusOK, notification) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func PutContent(db gorm.DB, router *gin.Engine) { // PUT /content // Update content data by id router.PUT("/content/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var contentData model.ContentData if err := c.BindJSON(&contentData); err == nil { content := &model.Content{ ContentData: contentData, ContentId: model.ContentId{Id: id}, } if err := checkDataContent(content.ContentData); err { checkContent := &model.Content{ ContentData: contentData, ContentId: model.ContentId{Id: id}, } if err := db.First(checkContent).Error; err == nil { db.Save(&content) c.JSON(http.StatusOK, content) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func PostActivity(db gorm.DB, router *gin.Engine) { // POST /activity // POST new activity to database router.POST("/activity", func(c *gin.Context) { var activityData model.ActivityData if err := c.BindJSON(&activityData); err == nil { activity := &model.Activity{ ActivityData: activityData, } var x_user uint64 if resp := c.Request.Header.Get(userHeader); resp != "" { conv_user, _ := strconv.ParseUint(resp, 10, 64) x_user = conv_user activity.Trace.CreatedBy = x_user activity.Trace.UpdatedBy = x_user if err := checkDataActivity(activity.ActivityData); err { if err := db.Create(&activity).Error; err != nil { c.AbortWithError(http.StatusBadRequest, err) } else { c.JSON(http.StatusCreated, activity) } } else { c.AbortWithStatus(http.StatusBadRequest) } } else { c.AbortWithStatus(http.StatusForbidden) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func PostSpaceSetting(db gorm.DB, router *gin.Engine) { // POST /space_setting // POST new space_setting to database router.POST("/space_setting", func(c *gin.Context) { var space_settingData model.SpaceSettingData if err := c.BindJSON(&space_settingData); err == nil { space_setting := &model.SpaceSetting{ SpaceSettingData: space_settingData, } var x_user uint64 if resp := c.Request.Header.Get(userHeader); resp != "" { conv_user, _ := strconv.ParseUint(resp, 10, 64) x_user = conv_user space_setting.Trace.CreatedBy = x_user space_setting.Trace.UpdatedBy = x_user if err := checkDataSpaceSetting(space_setting.SpaceSettingData); err { if err := db.Create(&space_setting).Error; err != nil { c.AbortWithError(http.StatusBadRequest, err) } else { c.JSON(http.StatusCreated, space_setting) } } else { c.AbortWithStatus(http.StatusBadRequest) } } else { c.AbortWithStatus(http.StatusForbidden) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func PostGroupAdmin(db gorm.DB, router *gin.Engine) { // POST /group_admin // POST new group_admin to database router.POST("/group_admin", func(c *gin.Context) { var group_adminData model.GroupAdminData if err := c.BindJSON(&group_adminData); err == nil { group_admin := &model.GroupAdmin{ GroupAdminData: group_adminData, } var x_user uint64 if resp := c.Request.Header.Get(userHeader); resp != "" { conv_user, _ := strconv.ParseUint(resp, 10, 64) x_user = conv_user group_admin.Trace.CreatedBy = x_user group_admin.Trace.UpdatedBy = x_user if err := checkDataGroupAdmin(group_admin.GroupAdminData); err { if err := db.Create(&group_admin).Error; err != nil { c.AbortWithError(http.StatusBadRequest, err) } else { c.JSON(http.StatusCreated, group_admin) } } else { c.AbortWithStatus(http.StatusBadRequest) } } else { c.AbortWithStatus(http.StatusForbidden) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func PutSpaceSetting(db gorm.DB, router *gin.Engine) { // PUT /space_setting // Update space_setting data by id router.PUT("/space_setting/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var space_settingData model.SpaceSettingData if err := c.BindJSON(&space_settingData); err == nil { space_setting := &model.SpaceSetting{ SpaceSettingData: space_settingData, SpaceSettingId: model.SpaceSettingId{Id: id}, } if err := checkDataSpaceSetting(space_setting.SpaceSettingData); err { checkSpaceSetting := &model.SpaceSetting{ SpaceSettingData: space_settingData, SpaceSettingId: model.SpaceSettingId{Id: id}, } if err := db.First(checkSpaceSetting).Error; err == nil { db.Save(&space_setting) c.JSON(http.StatusOK, space_setting) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func PostWallEntry(db gorm.DB, router *gin.Engine) { // POST /wall_entry // POST new wall_entry to database router.POST("/wall_entry", func(c *gin.Context) { var wall_entryData model.WallEntryData if err := c.BindJSON(&wall_entryData); err == nil { wall_entry := &model.WallEntry{ WallEntryData: wall_entryData, } var x_user uint64 if resp := c.Request.Header.Get(userHeader); resp != "" { conv_user, _ := strconv.ParseUint(resp, 10, 64) x_user = conv_user wall_entry.Trace.CreatedBy = x_user wall_entry.Trace.UpdatedBy = x_user if err := checkDataWallEntry(wall_entry.WallEntryData); err { if err := db.Create(&wall_entry).Error; err != nil { c.AbortWithError(http.StatusBadRequest, err) } else { c.JSON(http.StatusCreated, wall_entry) } } else { c.AbortWithStatus(http.StatusBadRequest) } } else { c.AbortWithStatus(http.StatusForbidden) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func PostUserPassword(db gorm.DB, router *gin.Engine) { // POST /user_password // POST new user_password to database router.POST("/user_password", func(c *gin.Context) { var user_passwordData model.UserPasswordData if err := c.BindJSON(&user_passwordData); err == nil { user_password := &model.UserPassword{ UserPasswordData: user_passwordData, } var x_user uint64 if resp := c.Request.Header.Get(userHeader); resp != "" { conv_user, _ := strconv.ParseUint(resp, 10, 64) x_user = conv_user user_password.Trace.CreatedBy = x_user user_password.Trace.UpdatedBy = x_user if err := checkDataUserPassword(user_password.UserPasswordData); err { if err := db.Create(&user_password).Error; err != nil { c.AbortWithError(http.StatusBadRequest, err) } else { c.JSON(http.StatusCreated, user_password) } } else { c.AbortWithStatus(http.StatusBadRequest) } } else { c.AbortWithStatus(http.StatusForbidden) } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func PutFile(db gorm.DB, router *gin.Engine) { // PUT /file // Update file data by id router.PUT("/file/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var fileData model.FileData if err := c.BindJSON(&fileData); err == nil { file := &model.File{ FileData: fileData, FileId: model.FileId{Id: id}, } if err := checkDataFile(file.FileData); err { checkFile := &model.File{ FileData: fileData, FileId: model.FileId{Id: id}, } if err := db.First(checkFile).Error; err == nil { db.Save(&file) c.JSON(http.StatusOK, file) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func registerRoutes(server *gin.Engine) { podRoute := server.Group("/pod") { podRoute.POST("/create", PodCreate) podRoute.GET("/state/:pod", PodState) } }
func PutLike(db gorm.DB, router *gin.Engine) { // PUT /like // Update like data by id router.PUT("/like/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var likeData model.LikeData if err := c.BindJSON(&likeData); err == nil { like := &model.Like{ LikeData: likeData, LikeId: model.LikeId{Id: id}, } if err := checkDataLike(like.LikeData); err { checkLike := &model.Like{ LikeData: likeData, LikeId: model.LikeId{Id: id}, } if err := db.First(checkLike).Error; err == nil { db.Save(&like) c.JSON(http.StatusOK, like) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func (m *Armor) RunWithRPC(g *gin.Engine, rpcInit func(*grpc.Server)) { runOn := fmt.Sprintf("%s:%s", m.Config.GetString("interface"), m.Config.GetString("port")) banner := ` A R M O R .---.___.---. | | | Running .....: PRODUCT_NAME |_____|_____| Host/Iface ..: HOST/INTERFACE |___|___| |___|___| ` // XXX replace with tmpl banner = strings.Replace( strings.Replace( strings.Replace(banner, "HOST", m.Config.Hostname, -1), "PRODUCT_NAME", m.Config.Product, -1), "INTERFACE", runOn, -1) log.Print(banner) log.Printf("-> Environment: %v", m.Config.Environment) log.Printf("-> Product: %v", m.Config.Product) log.Printf("-> Host/Interface: %v/%v", m.Config.Hostname, runOn) log.Printf("-> Config: %v", m.Config.All()) if rpcInit != nil { rpc := newRPC(m.Config) rpc.Run(rpcInit) } g.Run(runOn) }
func PutUserHttpSession(db gorm.DB, router *gin.Engine) { // PUT /user_http_session // Update user_http_session data by id router.PUT("/user_http_session/:id", func(c *gin.Context) { _id := c.Param("id") if id, err := strconv.ParseUint(_id, 10, 64); err == nil { var user_http_sessionData model.UserHttpSessionData if err := c.BindJSON(&user_http_sessionData); err == nil { user_http_session := &model.UserHttpSession{ UserHttpSessionData: user_http_sessionData, UserHttpSessionId: model.UserHttpSessionId{Id: id}, } if err := checkDataUserHttpSession(user_http_session.UserHttpSessionData); err { checkUserHttpSession := &model.UserHttpSession{ UserHttpSessionData: user_http_sessionData, UserHttpSessionId: model.UserHttpSessionId{Id: id}, } if err := db.First(checkUserHttpSession).Error; err == nil { db.Save(&user_http_session) c.JSON(http.StatusOK, user_http_session) } else { c.AbortWithStatus(http.StatusNotFound) } } else { c.AbortWithStatus(http.StatusBadRequest) } } } else { log.Print(err) c.AbortWithError(http.StatusBadRequest, err) } }) }
func sanityCheck(r *gin.Engine) { r.GET("/sanity-check.json", func(c *gin.Context) { type tool struct { Name string `json:"name"` Description string `json:"description"` Homepage string `json:"homepage"` Installed bool `json:"installed"` } var sanity = *GetSanityCheck() c.JSON(200, gin.H{ "tools": []tool{ tool{Name: "LaTeX", Description: "Compiles Tex", Homepage: "https://www.latex-project.org", Installed: sanity.latex}, tool{Name: "pdflatex", Description: "Converts .tex to .pdf", Homepage: "https://www.latex-project.org", Installed: sanity.pdflatex}, tool{Name: "convert", Description: "Converts .pdf to .png", Homepage: "http://www.imagemagick.org/script/index.php", Installed: sanity.convert}, }, }) }) r.GET("/sanity-check", func(c *gin.Context) { var sanity = *GetSanityCheck() c.HTML(200, "sanity-check.tmpl", gin.H{ "latex": sanity.latex, "pdflatex": sanity.pdflatex, "convert": sanity.convert, }) }) }