From 73ea7e41ccae7e0ca483b49e150c276253a88be9 Mon Sep 17 00:00:00 2001 From: Richard Park Date: Fri, 8 Nov 2019 00:07:41 +0900 Subject: [PATCH] boilerplate is added --- .vscode/launch.json | 26 ++++++++++++++++++++++++++ cmd/server/main.go | 16 +++++++++++++++- go.mod | 4 ++-- pkg/modules/user/handlers/users.go | 15 +++++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 pkg/modules/user/handlers/users.go diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..3215f14 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch - Server main", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${workspaceFolder}/cmd/server/main.go", + "env": {}, + "args": [] + }, + { + "name": "Launch - file", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${fileDirname}", + "env": {}, + "args": [] + } + ] +} \ No newline at end of file diff --git a/cmd/server/main.go b/cmd/server/main.go index 7905807..488e440 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -1,5 +1,19 @@ package main -func main() { +import ( + "log" + "github.com/buaazp/fasthttprouter" + "github.com/valyala/fasthttp" + + userHandlers "git.loafle.net/totopia/server/pkg/modules/user/handlers" +) + +func main() { + router := fasthttprouter.New() + + router.GET("/user/users", userHandlers.GetUsers) + router.POST("/user/users", userHandlers.PostUsers) + + log.Fatal(fasthttp.ListenAndServe(":8080", router.Handler)) } diff --git a/go.mod b/go.mod index 500451f..6d46576 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,6 @@ module git.loafle.net/totopia/server go 1.13 require ( - github.com/buaazp/fasthttprouter v0.1.1 // indirect - github.com/valyala/fasthttp v1.6.0 // indirect + github.com/buaazp/fasthttprouter v0.1.1 + github.com/valyala/fasthttp v1.6.0 ) diff --git a/pkg/modules/user/handlers/users.go b/pkg/modules/user/handlers/users.go new file mode 100644 index 0000000..276b4b6 --- /dev/null +++ b/pkg/modules/user/handlers/users.go @@ -0,0 +1,15 @@ +package users + +import ( + "fmt" + + "github.com/valyala/fasthttp" +) + +func GetUsers(ctx *fasthttp.RequestCtx) { + fmt.Fprintf(ctx, "hello, %s!\n", ctx.UserValue("name")) +} + +func PostUsers(ctx *fasthttp.RequestCtx) { + fmt.Fprintf(ctx, "hello, %s!\n", ctx.UserValue("name")) +}