Skip to content

Commit

Permalink
Merge pull request #2 from zakirkun/patch-1
Browse files Browse the repository at this point in the history
Refactor base
  • Loading branch information
zakirkun authored Jun 10, 2023
2 parents e8cbf9d + 7758f15 commit ba33987
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
12 changes: 0 additions & 12 deletions config.toml.example

This file was deleted.

16 changes: 12 additions & 4 deletions cmd/main.go → example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"os"
"time"

"github.com/zakirkun/infra-go/example/models"
routers "github.com/zakirkun/infra-go/example/routers"
"github.com/zakirkun/infra-go/infrastructure"
"github.com/zakirkun/infra-go/internal/config"
"github.com/zakirkun/infra-go/internal/database"
"github.com/zakirkun/infra-go/internal/server"
"github.com/zakirkun/infra-go/routers"
)

var configFile *string
Expand All @@ -23,9 +24,11 @@ func init() {
func main() {
setConfig()

infrastructure := infrastructure.NewInfrastructure(SetDatabase(), SetWebServer())
infrastructure.Database()
infrastructure.WebServer()
infra := infrastructure.NewInfrastructure(SetDatabase(), SetWebServer())
infra.Database()
SetMigration()

infra.WebServer()
}

func setConfig() {
Expand All @@ -36,6 +39,11 @@ func setConfig() {
}
}

func SetMigration() {
err := database.NewMigration(models.Account{})
log.Printf("Migration Info : %v", err)
}

func SetDatabase() database.DBModel {
return database.DBModel{
ServerMode: config.GetString("server.mode"),
Expand Down
11 changes: 11 additions & 0 deletions example/models/account.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package models

import "gorm.io/gorm"

type Account struct {
*gorm.Model

Username string `db:"username"`
Avatar string `db:"avatar"`
FullName string `db:"full_name"`
}
5 changes: 4 additions & 1 deletion routers/routers.go → example/routers/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"

"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
Expand All @@ -22,7 +23,9 @@ func InitRouters() http.Handler {
LogRoutePath: true,
LogHost: true,
BeforeNextFunc: func(c echo.Context) {
// c.Set("customValueFromContext", 42)
if c.Request().Header.Get(echo.HeaderXRequestID) == "" {
c.Request().Header.Set(echo.HeaderXRequestID, uuid.NewString())
}
},
LogValuesFunc: func(c echo.Context, v middleware.RequestLoggerValues) error {
fmt.Printf("[%v] REQUEST: uri: %v, Host: %v, Method: %v, UserAgent: %v, RoutePath: %v, IP: %v\n", v.RequestID, v.URI, v.Host, v.Method, v.UserAgent, v.RoutePath, v.RemoteIP)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
Expand Down

0 comments on commit ba33987

Please sign in to comment.