Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
cnf "github.com/project-ginza/notifications/config"
logging "github.com/project-ginza/notifications/log"
router "github.com/project-ginza/notifications/route"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"os"
Expand All @@ -26,6 +27,13 @@ func run(cmd *cobra.Command, args []string) {
logLevel := cnf.GlobalConfig.LogLevel
setLogConfig(logLevel)

r := router.GetRouter()
// The application runs with port 7000.
if err := r.Run(":7000"); err != nil {
errMsg := fmt.Sprintf("Failed to run Gin Framework. %v", err)
loggingCh.PushErrorMessageToChannel(errMsg)
}

<-sigs
}

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ module github.com/project-ginza/notifications
go 1.16

require (
github.com/gin-gonic/gin v1.7.7
github.com/lib/pq v1.10.4
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v1.4.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.10.1
gorm.io/driver/postgres v1.3.1
gorm.io/gorm v1.23.3
Expand Down
18 changes: 18 additions & 0 deletions request/request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package request

import (
"github.com/gin-gonic/gin"
logging "github.com/project-ginza/notifications/log"
"net/http"
)

var code string = "code"
var message string = "message"
var loggingCh = logging.LoggingCh

func Home(c *gin.Context) {
loggingCh.PushDebugMessageToChannel("home")
c.JSON(http.StatusOK, gin.H{
code: http.StatusOK,
})
}
14 changes: 14 additions & 0 deletions route/route.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package router

import (
"github.com/gin-gonic/gin"
"github.com/project-ginza/notifications/request"
)

func GetRouter() *gin.Engine {
router := gin.Default()

router.GET("/", request.Home)

return router
}