From 859d56ab1a025f26242f441213be47e06d72d000 Mon Sep 17 00:00:00 2001 From: darius Date: Thu, 16 May 2024 17:59:21 +0200 Subject: [PATCH] refactor + docs added --- .github/workflows/Deploy-docker.yml | 2 +- Writerside/c.list | 6 ++ Writerside/cfg/buildprofiles.xml | 12 ++++ Writerside/portfolio.tree | 9 +++ Writerside/redirection-rules.xml | 21 +++++++ .../topics/openApi.json/API_Reference.md | 3 + Writerside/v.list | 5 ++ Writerside/writerside.cfg | 8 +++ api/apiRoutes.go | 15 ----- api/docs/openAPI/go.mod | 3 + api/docs/openAPI/openApi.go | 31 +++++++++++ api/handler/projectHandler.go | 1 - api/{handler => handlers}/authHandler.go | 2 +- api/{handler => handlers}/errorHandlers.go | 2 +- api/{handler => handlers}/mainHandler.go | 2 +- api/handlers/projectHandler.go | 1 + api/{handler => handlers}/userHandler.go | 2 +- {types => api/types}/userTypes.go | 0 api/webRoutes.go | 19 ------- go.mod | 15 ++++- go.sum | 55 ++++++++++++++----- go.work | 6 ++ main.go | 24 +++++--- routes/apiRoutes.go | 20 +++++++ routes/webRoutes.go | 24 ++++++++ .../handlers}/aboutpageHandler.go | 2 +- .../handlers}/homepageHandler.go | 2 +- .../handlers}/loginpageHandler.go | 2 +- .../handlers}/projectpageHandler.go | 4 +- 29 files changed, 229 insertions(+), 69 deletions(-) create mode 100644 Writerside/c.list create mode 100644 Writerside/cfg/buildprofiles.xml create mode 100644 Writerside/portfolio.tree create mode 100644 Writerside/redirection-rules.xml create mode 100644 Writerside/topics/openApi.json/API_Reference.md create mode 100644 Writerside/v.list create mode 100644 Writerside/writerside.cfg delete mode 100644 api/apiRoutes.go create mode 100644 api/docs/openAPI/go.mod create mode 100644 api/docs/openAPI/openApi.go delete mode 100644 api/handler/projectHandler.go rename api/{handler => handlers}/authHandler.go (98%) rename api/{handler => handlers}/errorHandlers.go (96%) rename api/{handler => handlers}/mainHandler.go (92%) create mode 100644 api/handlers/projectHandler.go rename api/{handler => handlers}/userHandler.go (98%) rename {types => api/types}/userTypes.go (100%) delete mode 100644 api/webRoutes.go create mode 100644 go.work create mode 100644 routes/apiRoutes.go create mode 100644 routes/webRoutes.go rename {api/webHandler => web/handlers}/aboutpageHandler.go (95%) rename {api/webHandler => web/handlers}/homepageHandler.go (97%) rename {api/webHandler => web/handlers}/loginpageHandler.go (95%) rename {api/webHandler => web/handlers}/projectpageHandler.go (92%) diff --git a/.github/workflows/Deploy-docker.yml b/.github/workflows/Deploy-docker.yml index 6629ff9..fc653d4 100644 --- a/.github/workflows/Deploy-docker.yml +++ b/.github/workflows/Deploy-docker.yml @@ -21,7 +21,7 @@ jobs: - name: Build the Docker image run: docker compose build - name: Docker push - run: docker push docker.dariusklein.nl/portfolio-api1:latest + run: docker push docker.dariusklein.nl/portfolio:latest publish: diff --git a/Writerside/c.list b/Writerside/c.list new file mode 100644 index 0000000..c4c77a2 --- /dev/null +++ b/Writerside/c.list @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/Writerside/cfg/buildprofiles.xml b/Writerside/cfg/buildprofiles.xml new file mode 100644 index 0000000..b2ef709 --- /dev/null +++ b/Writerside/cfg/buildprofiles.xml @@ -0,0 +1,12 @@ + + + + + + + true + + + + diff --git a/Writerside/portfolio.tree b/Writerside/portfolio.tree new file mode 100644 index 0000000..8604aa6 --- /dev/null +++ b/Writerside/portfolio.tree @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/Writerside/redirection-rules.xml b/Writerside/redirection-rules.xml new file mode 100644 index 0000000..2f21662 --- /dev/null +++ b/Writerside/redirection-rules.xml @@ -0,0 +1,21 @@ + + + + + + Created after removal of "Schemas" from portfolio + Schemas.html + + + Created after removal of "API Reference" from portfolio + API_Reference.html + + + Created after removal of "About portfolio" from portfolio + starter-topic.html + + \ No newline at end of file diff --git a/Writerside/topics/openApi.json/API_Reference.md b/Writerside/topics/openApi.json/API_Reference.md new file mode 100644 index 0000000..158d9a3 --- /dev/null +++ b/Writerside/topics/openApi.json/API_Reference.md @@ -0,0 +1,3 @@ +# API Reference + +Start typing here... \ No newline at end of file diff --git a/Writerside/v.list b/Writerside/v.list new file mode 100644 index 0000000..2d12cb3 --- /dev/null +++ b/Writerside/v.list @@ -0,0 +1,5 @@ + + + + + diff --git a/Writerside/writerside.cfg b/Writerside/writerside.cfg new file mode 100644 index 0000000..7a9e6f6 --- /dev/null +++ b/Writerside/writerside.cfg @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/api/apiRoutes.go b/api/apiRoutes.go deleted file mode 100644 index 5ba8f1c..0000000 --- a/api/apiRoutes.go +++ /dev/null @@ -1,15 +0,0 @@ -package api - -import ( - "net/http" - "portfolio/api/handler" -) - -func ApiRoutes(mux **http.ServeMux) { - m := *mux - // Register the routes and webHandler - m.HandleFunc("/api/", handler.CatchAllHandler) - m.HandleFunc("POST /api/user", handler.CreateUser) - m.HandleFunc("GET /api/user/{id}", handler.GetUser) - m.HandleFunc("POST /api/login", handler.Login) -} diff --git a/api/docs/openAPI/go.mod b/api/docs/openAPI/go.mod new file mode 100644 index 0000000..a6c5405 --- /dev/null +++ b/api/docs/openAPI/go.mod @@ -0,0 +1,3 @@ +module openAPI + +go 1.22 diff --git a/api/docs/openAPI/openApi.go b/api/docs/openAPI/openApi.go new file mode 100644 index 0000000..0ff3b51 --- /dev/null +++ b/api/docs/openAPI/openApi.go @@ -0,0 +1,31 @@ +package main + +import ( + "encoding/json" + "github.com/a-h/rest" + "log" + "os" +) + +var api *rest.API + +func main() { + // Configure the models. + api = rest.NewAPI("portfolio") + api.StripPkgPaths = []string{"github.com/a-h/rest/example", "github.com/a-h/respond"} + + // Create the specification. + spec, err := api.Spec() + if err != nil { + log.Fatalf("failed to create spec: %v", err) + } + + // create file + file, _ := os.OpenFile("common/docs/openApi.json", os.O_CREATE, os.ModePerm) + defer file.Close() + + // Write to file + enc := json.NewEncoder(file) + enc.SetIndent("", " ") + enc.Encode(spec) +} diff --git a/api/handler/projectHandler.go b/api/handler/projectHandler.go deleted file mode 100644 index abeebd1..0000000 --- a/api/handler/projectHandler.go +++ /dev/null @@ -1 +0,0 @@ -package handler diff --git a/api/handler/authHandler.go b/api/handlers/authHandler.go similarity index 98% rename from api/handler/authHandler.go rename to api/handlers/authHandler.go index 1720e57..045d023 100644 --- a/api/handler/authHandler.go +++ b/api/handlers/authHandler.go @@ -1,4 +1,4 @@ -package handler +package handlers import ( "context" diff --git a/api/handler/errorHandlers.go b/api/handlers/errorHandlers.go similarity index 96% rename from api/handler/errorHandlers.go rename to api/handlers/errorHandlers.go index 508e6cf..2833b69 100644 --- a/api/handler/errorHandlers.go +++ b/api/handlers/errorHandlers.go @@ -1,4 +1,4 @@ -package handler +package handlers import "net/http" diff --git a/api/handler/mainHandler.go b/api/handlers/mainHandler.go similarity index 92% rename from api/handler/mainHandler.go rename to api/handlers/mainHandler.go index 172342d..93135e3 100644 --- a/api/handler/mainHandler.go +++ b/api/handlers/mainHandler.go @@ -1,4 +1,4 @@ -package handler +package handlers import "net/http" diff --git a/api/handlers/projectHandler.go b/api/handlers/projectHandler.go new file mode 100644 index 0000000..5ac8282 --- /dev/null +++ b/api/handlers/projectHandler.go @@ -0,0 +1 @@ +package handlers diff --git a/api/handler/userHandler.go b/api/handlers/userHandler.go similarity index 98% rename from api/handler/userHandler.go rename to api/handlers/userHandler.go index c3fa915..22c0620 100644 --- a/api/handler/userHandler.go +++ b/api/handlers/userHandler.go @@ -1,4 +1,4 @@ -package handler +package handlers import ( "context" diff --git a/types/userTypes.go b/api/types/userTypes.go similarity index 100% rename from types/userTypes.go rename to api/types/userTypes.go diff --git a/api/webRoutes.go b/api/webRoutes.go deleted file mode 100644 index 1cb5a3e..0000000 --- a/api/webRoutes.go +++ /dev/null @@ -1,19 +0,0 @@ -package api - -import ( - "net/http" - "portfolio/api/webHandler" -) - -func WebRoutes(mux **http.ServeMux) { - m := *mux - // Register the routes and webHandler - m.HandleFunc("GET /{$}", webHandler.InitHomepage) - m.HandleFunc("GET /projecten/{$}", webHandler.InitProjectpage) - m.HandleFunc("GET /about/{$}", webHandler.InitAboutpage) - m.HandleFunc("GET /login/{$}", webHandler.InitLoginpage) - - m.HandleFunc("POST /theme", webHandler.UpdateTheme) - - m.HandleFunc("GET /test", webHandler.Test) -} diff --git a/go.mod b/go.mod index fac48ba..7ed85f7 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.22 require ( entgo.io/ent v0.13.1 + github.com/a-h/rest v0.0.0-20240504113546-6729b3328f85 github.com/joho/godotenv v1.5.1 github.com/lib/pq v1.10.9 golang.org/x/crypto v0.23.0 @@ -13,12 +14,24 @@ require ( ariga.io/atlas v0.19.1-0.20240203083654-5948b60a8e43 // indirect github.com/agext/levenshtein v1.2.3 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect + github.com/getkin/kin-openapi v0.124.0 // indirect github.com/go-openapi/inflect v0.19.0 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect + github.com/go-openapi/swag v0.23.0 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/hcl/v2 v2.19.1 // indirect + github.com/invopop/yaml v0.3.1 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/mailru/easyjson v0.7.7 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect + github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect + github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/zclconf/go-cty v1.14.2 // indirect - golang.org/x/mod v0.15.0 // indirect + golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/sync v0.7.0 // indirect golang.org/x/text v0.15.0 // indirect + golang.org/x/tools v0.20.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 21f8cfd..0d7e1da 100644 --- a/go.sum +++ b/go.sum @@ -4,16 +4,24 @@ entgo.io/ent v0.13.1 h1:uD8QwN1h6SNphdCCzmkMN3feSUzNnVvV/WIkHKMbzOE= entgo.io/ent v0.13.1/go.mod h1:qCEmo+biw3ccBn9OyL4ZK5dfpwg++l1Gxwac5B1206A= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= +github.com/a-h/rest v0.0.0-20240504113546-6729b3328f85 h1:Lj+OmK3+dKMuR8OdlnUeIrgdt8JkcNlA9isS2Aey5Mg= +github.com/a-h/rest v0.0.0-20240504113546-6729b3328f85/go.mod h1:5wH1imbpKnMjll8xpGRdg0Sb0HwH7nYiM5VPm0Zl5Bw= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/getkin/kin-openapi v0.124.0 h1:VSFNMB9C9rTKBnQ/fpyDU8ytMTr4dWI9QovSKj9kz/M= +github.com/getkin/kin-openapi v0.124.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM= github.com/go-openapi/inflect v0.19.0 h1:9jCH9scKIbHeV9m12SmPilScz6krDxKRasNNSNPXu/4= github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= -github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68= -github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= +github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= +github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -22,47 +30,66 @@ github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5R github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso= +github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y= github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= +github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= +github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s= +github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0= +github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY= github.com/zclconf/go-cty v1.14.2 h1:kTG7lqmBou0Zkx35r6HJHUQTvaRPr5bIAf3AoHS0izI= github.com/zclconf/go-cty v1.14.2/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= -golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= -golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= -golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8 h1:ESSUROHIBHg7USnszlcdmjBEwdMj9VUvU+OPk4yl2mc= +golang.org/x/exp v0.0.0-20240409090435-93d18d7e34b8/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ= -golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg= +golang.org/x/tools v0.20.0 h1:hz/CVckiOxybQvFw6h7b/q80NTr9IUQb4s1IIzW7KNY= +golang.org/x/tools v0.20.0/go.mod h1:WvitBU7JJf6A4jOdg4S1tviW9bhUxkgeCui/0JHctQg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= +gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go.work b/go.work new file mode 100644 index 0000000..0e1247e --- /dev/null +++ b/go.work @@ -0,0 +1,6 @@ +go 1.22 + +use ( + api/docs/openAPI + . +) \ No newline at end of file diff --git a/main.go b/main.go index cfefbcc..5061aa5 100644 --- a/main.go +++ b/main.go @@ -4,8 +4,8 @@ import ( "github.com/joho/godotenv" "log" "net/http" - "portfolio/api" "portfolio/database" + "portfolio/routes" ) func main() { @@ -16,17 +16,23 @@ func main() { return } - // Create a new request multiplexer - // Take incoming requests and dispatch them to the matching webHandler - mux := http.NewServeMux() - - api.WebRoutes(&mux) - - api.ApiRoutes(&mux) + //init web routes + web := routes.WebRoutes() + //init api routes + api := routes.ApiRoutes() //connect to database and migrate database.DB() // Run the server - http.ListenAndServe(":4002", mux) + err = http.ListenAndServe(":4001", web) + if err != nil { + log.Fatalf("web failed to start: %v", err) + return + } + err = http.ListenAndServe(":4002", api) + if err != nil { + log.Fatalf("api failed to start: %v", err) + return + } } diff --git a/routes/apiRoutes.go b/routes/apiRoutes.go new file mode 100644 index 0000000..572bf62 --- /dev/null +++ b/routes/apiRoutes.go @@ -0,0 +1,20 @@ +package routes + +import ( + "net/http" + "portfolio/api/handlers" +) + +func ApiRoutes() *http.ServeMux { + // Create a new request multiplexer + // Take incoming requests and dispatch them to the matching webHandler + mux := http.NewServeMux() + + // Register the routes and webHandler + mux.HandleFunc("/api/", handlers.CatchAllHandler) + mux.HandleFunc("POST /api/user", handlers.CreateUser) + mux.HandleFunc("GET /api/user/{id}", handlers.GetUser) + mux.HandleFunc("POST /api/login", handlers.Login) + + return mux +} diff --git a/routes/webRoutes.go b/routes/webRoutes.go new file mode 100644 index 0000000..023eaf2 --- /dev/null +++ b/routes/webRoutes.go @@ -0,0 +1,24 @@ +package routes + +import ( + "net/http" + "portfolio/web/handlers" +) + +func WebRoutes() *http.ServeMux { + // Create a new request multiplexer + // Take incoming requests and dispatch them to the matching webHandler + mux := http.NewServeMux() + + // Register the routes and webHandler + mux.HandleFunc("GET /{$}", handlers.InitHomepage) + mux.HandleFunc("GET /projecten/{$}", handlers.InitProjectpage) + mux.HandleFunc("GET /about/{$}", handlers.InitAboutpage) + mux.HandleFunc("GET /login/{$}", handlers.InitLoginpage) + + mux.HandleFunc("POST /theme", handlers.UpdateTheme) + + mux.HandleFunc("GET /test", handlers.Test) + + return mux +} diff --git a/api/webHandler/aboutpageHandler.go b/web/handlers/aboutpageHandler.go similarity index 95% rename from api/webHandler/aboutpageHandler.go rename to web/handlers/aboutpageHandler.go index eed753c..20c47d6 100644 --- a/api/webHandler/aboutpageHandler.go +++ b/web/handlers/aboutpageHandler.go @@ -1,4 +1,4 @@ -package webHandler +package handlers import ( "html/template" diff --git a/api/webHandler/homepageHandler.go b/web/handlers/homepageHandler.go similarity index 97% rename from api/webHandler/homepageHandler.go rename to web/handlers/homepageHandler.go index 3561c5c..49300dd 100644 --- a/api/webHandler/homepageHandler.go +++ b/web/handlers/homepageHandler.go @@ -1,4 +1,4 @@ -package webHandler +package handlers import ( "html/template" diff --git a/api/webHandler/loginpageHandler.go b/web/handlers/loginpageHandler.go similarity index 95% rename from api/webHandler/loginpageHandler.go rename to web/handlers/loginpageHandler.go index 00159e6..c351f1c 100644 --- a/api/webHandler/loginpageHandler.go +++ b/web/handlers/loginpageHandler.go @@ -1,4 +1,4 @@ -package webHandler +package handlers import ( "html/template" diff --git a/api/webHandler/projectpageHandler.go b/web/handlers/projectpageHandler.go similarity index 92% rename from api/webHandler/projectpageHandler.go rename to web/handlers/projectpageHandler.go index a60221a..a1d2132 100644 --- a/api/webHandler/projectpageHandler.go +++ b/web/handlers/projectpageHandler.go @@ -1,9 +1,9 @@ -package webHandler +package handlers import ( "html/template" "net/http" - "portfolio/types" + "portfolio/api/types" ) func InitProjectpage(w http.ResponseWriter, r *http.Request) {