From 3ce6b96597c4460a35ecfaa5715daae82dc48279 Mon Sep 17 00:00:00 2001 From: Araozu Date: Fri, 3 May 2024 10:59:20 -0500 Subject: [PATCH] Go start --- go.mod | 8 ++++++++ go.sum | 4 ++++ main.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..036a3ac --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module git.araozu.dev/card-jong-be + +go 1.22.2 + +require ( + github.com/gorilla/mux v1.8.1 // indirect + github.com/rs/cors v1.11.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..cb2e461 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= +github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= +github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po= +github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= diff --git a/main.go b/main.go new file mode 100644 index 0000000..074dcdd --- /dev/null +++ b/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "log" + "net/http" + "os" + + "github.com/gorilla/mux" + "github.com/rs/cors" +) + +func main() { + fmt.Println("hello SEKAI!!") + router := mux.NewRouter().PathPrefix("/api").Subrouter() + + router.HandleFunc("/register", Register) + + port, ok := os.LookupEnv("PORT") + if !ok { + port = "8080" + } + + cors := cors.New(cors.Options{ + AllowedOrigins: []string{"http://localhost:3000"}, + AllowedMethods: []string{"GET", "DELETE", "POST", "PUT", "OPTIONS"}, + AllowedHeaders: []string{"Content-Type", "Origin", "Accept", "Authorization"}, + AllowCredentials: true, + }) + + handler := cors.Handler(router) + + log.Fatal(http.ListenAndServe(":"+port, handler)) +} + +type PersonInfo struct { + useruuid int + username string +} + +func Register(writer http.ResponseWriter, request *http.Request) { + writer.Header().Set("Content-Type", "application/json") + writer.WriteHeader(http.StatusOK) + fmt.Fprintf(writer, "{\"yes\":\"and\"}") +}