-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Separate implementation logic & create networks endpoint 🚀
- Loading branch information
1 parent
5129de2
commit 174c599
Showing
8 changed files
with
62 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ main | |
|
||
# Go workspace file | ||
go.work | ||
go.sum | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
FROM golang:latest | ||
FROM golang:1.17 | ||
|
||
RUN mkdir /app | ||
WORKDIR /app | ||
ADD src /app | ||
|
||
RUN go get github.com/githubnemo/CompileDaemon | ||
RUN go install github.com/githubnemo/CompileDaemon | ||
RUN go install github.com/gin-gonic/gin | ||
RUN go install github.com/githubnemo/CompileDaemon@latest | ||
|
||
# Needs go.mod file (go mod init main + go mod tidy) | ||
RUN go get -u | ||
ENTRYPOINT CompileDaemon --build="go build main.go" --command=./main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package api | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
networks "main/api/networks" | ||
) | ||
|
||
func InitRouters() *gin.Engine { | ||
router := gin.Default() | ||
setUpRouter(router) | ||
return router | ||
} | ||
|
||
func setUpRouter(router *gin.Engine) { | ||
api := router.Group("/api") | ||
{ | ||
networks.RegisterRouter(api.Group("/networks")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package networks | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func addNetworks(c *gin.Context) { | ||
c.JSON(200, gin.H{"msg": "Hello from addNetworks"}) | ||
} | ||
|
||
func getNetworks(c *gin.Context) { | ||
c.JSON(200, gin.H{"msg": "Hello from getNetworks"}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package networks | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
func RegisterRouter(r *gin.RouterGroup) { | ||
r.POST("/", addNetworks) | ||
r.GET("/", getNetworks) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module go-lang-research | ||
module main | ||
|
||
go 1.17 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,10 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"github.com/gin-gonic/gin" | ||
"main/api" | ||
) | ||
|
||
type album struct { | ||
ID string `json:"id"` | ||
Title string `json:"title"` | ||
Artist string `json:"artist"` | ||
Price float32 `json:"price"` | ||
} | ||
|
||
var albums = []album { | ||
{ID: "1", Title: "Blue Train", Artist: "John Coltrane", Price: 56.99}, | ||
{ID: "2", Title: "Jeru", Artist: "Gerry Mulligan", Price: 17.99}, | ||
{ID: "3", Title: "Sarah Vaughan and Clifford Brown", Artist: "Sarah Vaughan", Price: 39.99}, | ||
{ID: "4", Title: "Lord of the Rings", Artist: "J.R.R. Tolkien", Price: 59.99}, | ||
} | ||
|
||
func main() { | ||
r := gin.New() | ||
r.GET("/albums", func(c *gin.Context) { | ||
c.JSON(http.StatusOK, albums) | ||
}) | ||
r := api.InitRouters() | ||
r.Run() | ||
} |