initial go backend
This commit is contained in:
parent
509622aec0
commit
28ebe953e0
11 changed files with 205 additions and 0 deletions
23
Lab01/app/api/api.go
Normal file
23
Lab01/app/api/api.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (api *Api) defineRoutes() {
|
||||
api.Router.GET("/ping", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"message": "pong",
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (api *Api) serve(address string) {
|
||||
api.Router = gin.Default()
|
||||
api.Router.Run(address)
|
||||
}
|
||||
|
||||
func (api *Api) Run() {
|
||||
api.defineRoutes()
|
||||
api.serve(":8080")
|
||||
}
|
11
Lab01/app/api/types.go
Normal file
11
Lab01/app/api/types.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"app/database"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type Api struct {
|
||||
Database database.Database
|
||||
Router *gin.Engine
|
||||
}
|
Reference in a new issue