Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge remote-tracking branch 'origin/main' into 39-feature-mod-echo-t… #45

Merged
merged 29 commits into from
Sep 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Ginへの移行
kynmh69 committed Sep 28, 2024
commit 79c586ef3bc4f8fa9d47027ecf2ce77ab443720d
3 changes: 1 addition & 2 deletions src/go.mod
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ go 1.22.0

require (
github.com/doug-martin/goqu/v9 v9.19.0
github.com/gin-contrib/multitemplate v1.0.1
github.com/gin-gonic/gin v1.10.0
github.com/labstack/echo/v4 v4.11.4
github.com/lib/pq v1.10.1
@@ -42,7 +43,6 @@ require (
)

require (
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/uuid v1.6.0
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
@@ -51,5 +51,4 @@ require (
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/time v0.5.0 // indirect
)
6 changes: 2 additions & 4 deletions src/go.sum
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ github.com/doug-martin/goqu/v9 v9.19.0 h1:PD7t1X3tRcUiSdc5TEyOFKujZA5gs3VSA7wxSv
github.com/doug-martin/goqu/v9 v9.19.0/go.mod h1:nf0Wc2/hV3gYK9LiyqIrzBEVGlI8qW3GuDCEobC4wBQ=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gin-contrib/multitemplate v1.0.1 h1:Asi8boB7NctSoQzbWDosLObon0cYMP5OM+ihQMjlW5M=
github.com/gin-contrib/multitemplate v1.0.1/go.mod h1:uU+PnuKoiEHWqB9Zvco+Kqv9KNrsHi6IZOUUgTctMPA=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU=
@@ -32,8 +34,6 @@ github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaC
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
@@ -128,8 +128,6 @@ golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
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/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
12 changes: 7 additions & 5 deletions src/key_management/controller/base.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package controller

import "github.com/labstack/echo/v4"
import (
"github.com/gin-gonic/gin"
)

type Controller interface {
Retrieve(c echo.Context) error
Create(c echo.Context) error
Update(c echo.Context) error
Delete(c echo.Context) error
Retrieve(r *gin.Context) error
Create(r *gin.Context) error
Update(r *gin.Context) error
Delete(r *gin.Context) error
GetControllerName() string
}
34 changes: 21 additions & 13 deletions src/key_management/controller/key.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package controller

import (
"errors"
"github.com/gin-gonic/gin"
"github.com/kynmh69/go-ja-holidays/logging"
"net/http"

"github.com/kynmh69/go-ja-holidays/model"
"github.com/labstack/echo/v4"
)

const (
@@ -17,25 +17,33 @@ type KeyManagement struct {
ControllerName string
}

func (k KeyManagement) Retrieve(c echo.Context) error {
logger := c.Logger()
func (k KeyManagement) Retrieve(c *gin.Context) {
logger := logging.GetLogger()
apiKeys, _ := model.GetApiKeys()
logger.Debug("APIKEYS", apiKeys)
return c.Render(http.StatusOK, TOP_PAGE_NAME, apiKeys)
c.HTML(http.StatusOK, TOP_PAGE_NAME, apiKeys)
}

func (k KeyManagement) Create(c echo.Context) error {
model.CreateApiKey(c)
return c.Redirect(http.StatusFound, TOP_PATH)
func (k KeyManagement) Create(c *gin.Context) {
err := model.CreateApiKey(c)
if err != nil {
c.HTML(500, "error", gin.H{"error": err.Error()})
return
}
c.Redirect(http.StatusFound, TOP_PATH)
}

func (k KeyManagement) Update(c echo.Context) error {
return errors.New("not implemented")
func (k KeyManagement) Update(c *gin.Context) {
c.HTML(500, "update", nil)
kynmh69 marked this conversation as resolved.
Show resolved Hide resolved
}

func (k KeyManagement) Delete(c echo.Context) error {
model.DeleteApiKey(c)
return c.Redirect(http.StatusFound, TOP_PATH)
func (k KeyManagement) Delete(c *gin.Context) {
err := model.DeleteApiKey(c)
if err != nil {
c.HTML(500, "error", gin.H{"error": err.Error()})
return
}
c.Redirect(http.StatusFound, TOP_PATH)
}

func (k KeyManagement) GetControllerName() string {
17 changes: 7 additions & 10 deletions src/key_management/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package main

import (
"github.com/gin-gonic/gin"
"github.com/kynmh69/go-ja-holidays/logging"
"os"

"github.com/kynmh69/go-ja-holidays/database"
"github.com/kynmh69/go-ja-holidays/key_management/router"
"github.com/kynmh69/go-ja-holidays/key_management/template"
"github.com/kynmh69/go-ja-holidays/util"
"github.com/labstack/echo/v4"
mid "github.com/labstack/echo/v4/middleware"
)

func init() {
@@ -18,14 +16,13 @@ func init() {
}

func main() {
e := echo.New()
e.Use(mid.Static("./static"))
logger := e.Logger
r := gin.Default()
r.Static("/static", "./static")
logger := logging.GetLogger()

t := template.NewTemplate("view/*.html")
e.Renderer = t
e.HTTPErrorHandler = util.CustomHTTPErrorHandler
router.MakeRoute(e)
r.HTMLRender = template.Render("view/*.html")
//e.HTTPErrorHandler = util.CustomHTTPErrorHandler
kynmh69 marked this conversation as resolved.
Show resolved Hide resolved
router.MakeRoute(r)
wd, _ := os.Getwd()
logger.Debug(wd)
logger.Fatal(e.Start(":80"))
12 changes: 6 additions & 6 deletions src/key_management/router/router.go
Original file line number Diff line number Diff line change
@@ -2,22 +2,22 @@ package router

import (
"fmt"
"github.com/gin-gonic/gin"
"log"

"github.com/kynmh69/go-ja-holidays/key_management/controller"
"github.com/labstack/echo/v4"
)

func MakeRoute(e *echo.Echo) {
func MakeRoute(r *gin.Engine) {
controllers := []controller.Controller{
controller.KeyManagement{ControllerName: "key"},
}
for _, v := range controllers {
path := fmt.Sprintf("/manage/%s", v.GetControllerName())
log.Println(path)
e.POST(fmt.Sprintf("%s/create", path), v.Create)
e.GET(path, v.Retrieve)
e.PUT(path, v.Update)
e.POST(fmt.Sprintf("%s/delete", path), v.Delete)
r.POST(fmt.Sprintf("%s/create", path), v.Create)
r.GET(path, v.Retrieve)
r.PUT(path, v.Update)
r.POST(fmt.Sprintf("%s/delete", path), v.Delete)
}
}
28 changes: 14 additions & 14 deletions src/key_management/template/template.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package template

import (
"html/template"
"io"

"github.com/labstack/echo/v4"
"github.com/gin-contrib/multitemplate"
"github.com/kynmh69/go-ja-holidays/logging"
"path/filepath"
)

type Template struct {
templates *template.Template
}
func Render(templateGlob string) multitemplate.Renderer {
logger := logging.GetLogger()
logger.Debug("Glob:", templateGlob)
r := multitemplate.NewRenderer()

func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
logger := c.Logger()
logger.Debug(w, name, data)
return t.templates.ExecuteTemplate(w, name, data)
}
layouts, err := filepath.Glob(templateGlob)
if err != nil {
logger.Panicln(err.Error())
}

func NewTemplate(path string) *Template {
return &Template{templates: template.Must(template.ParseGlob(path))}
// Generate our templates map from our layouts/ and includes/ directories
r.AddFromFiles("view", layouts...)
return r
}
11 changes: 6 additions & 5 deletions src/model/api_key.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package model

import (
"github.com/gin-gonic/gin"
"github.com/kynmh69/go-ja-holidays/logging"
"time"

"github.com/doug-martin/goqu/v9"
"github.com/google/uuid"
"github.com/kynmh69/go-ja-holidays/database"
"github.com/labstack/echo/v4"
)

const TABLE_API_KEY = "api_key"
@@ -26,8 +27,8 @@ func GetApiKeys() ([]ApiKey, error) {
return apiKeys, err
}

func CreateApiKey(c echo.Context) error {
logger := c.Logger()
func CreateApiKey(c *gin.Context) error {
logger := logging.GetLogger()
key := uuid.New()
db := database.GetDbConnection()
result, err := db.Insert(TABLE_API_KEY).
@@ -44,8 +45,8 @@ func CreateApiKey(c echo.Context) error {
return err
}

func DeleteApiKey(c echo.Context) error {
logger := c.Logger()
func DeleteApiKey(c *gin.Context) error {
logger := logging.GetLogger()
db := database.GetDbConnection()
defaultLocation := time.Local
logger.Debug(defaultLocation)