Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
51 changes: 22 additions & 29 deletions shared/templates/hexagonal/cmd/bootstrap/app_repository.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,49 +30,49 @@ func InitializeRepository() portregistry.Repository {
{{if .IsRedis}}
cacheRepository: redisadapter.New(
redisadapter.RedisOptions{
Addr: config.AppRepository.Cache.Redis.Addr,
Username: config.AppRepository.Cache.Redis.Username,
Password: config.AppRepository.Cache.Redis.Password,
DB: config.AppRepository.Cache.Redis.DB,
Addr: config.App.Cache.Redis.Addr,
Username: config.App.Cache.Redis.Username,
Password: config.App.Cache.Redis.Password,
DB: config.App.Cache.Redis.DB,
},
),
{{end}}

{{if .IsPSQL}}
psqlRepository: psqladapter.New(psqladapter.PSQLConfig{
Host: config.AppRepository.Datastore.PSQL.Host,
Port: config.AppRepository.Datastore.PSQL.Port,
Username: config.AppRepository.Datastore.PSQL.Username,
Password: config.AppRepository.Datastore.PSQL.Password,
DB: config.AppRepository.Datastore.PSQL.DB,
Host: config.App.Datastore.PSQL.Host,
Port: config.App.Datastore.PSQL.Port,
Username: config.App.Datastore.PSQL.Username,
Password: config.App.Datastore.PSQL.Password,
DB: config.App.Datastore.PSQL.DB,
}),
{{end}}

{{if .IsSQLite}}
sqliteRepository: sqliteadapter.New(sqliteadapter.SQLiteConfig{
Path: config.AppRepository.Datastore.SQLite.Path,
Mode: config.AppRepository.Datastore.SQLite.Mode, // Optional
Path: config.App.Datastore.SQLite.Path,
Mode: config.App.Datastore.SQLite.Mode, // Optional
}),
{{end}}

{{if .IsMySQL}}
mysqlRepository: mysqladapter.New(mysqladapter.MySQLConfig{
Host: config.AppRepository.Datastore.MySQL.Host,
Port: config.AppRepository.Datastore.MySQL.Port,
Username: config.AppRepository.Datastore.MySQL.Username,
Password: config.AppRepository.Datastore.MySQL.Password,
DB: config.AppRepository.Datastore.MySQL.DB,
Host: config.App.Datastore.MySQL.Host,
Port: config.App.Datastore.MySQL.Port,
Username: config.App.Datastore.MySQL.Username,
Password: config.App.Datastore.MySQL.Password,
DB: config.App.Datastore.MySQL.DB,
}),
{{end}}

{{if .IsMongoDB}}
mongoRepository: mongoadapter.New(mongoadapter.MongoConfig{
Host: config.AppRepository.Datastore.MongoDB.Host,
Port: config.AppRepository.Datastore.MongoDB.Port,
Username: config.AppRepository.Datastore.MongoDB.Username,
Password: config.AppRepository.Datastore.MongoDB.Password,
DB: config.AppRepository.Datastore.MongoDB.DB,
AuthDB: config.AppRepository.Datastore.MongoDB.AuthDB, // Optional
Host: config.App.Datastore.MongoDB.Host,
Port: config.App.Datastore.MongoDB.Port,
Username: config.App.Datastore.MongoDB.Username,
Password: config.App.Datastore.MongoDB.Password,
DB: config.App.Datastore.MongoDB.DB,
AuthDB: config.App.Datastore.MongoDB.AuthDB, // Optional
}),
{{end}}
}
Expand Down Expand Up @@ -150,10 +150,3 @@ func (a *AppRepository) MongoRepository() repository.MongoRepository {
return a.mongoRepository
}
{{end}}

{{- range .Repositories}}
func (a *AppRepository) Get{{.}}() repository.{{.}}{
return nil
}
{{- end}}

Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,22 @@ type Pagination struct {
Page *int `json:"page,omitempty"`
}

func Success(c *fiber.Ctx, data any) error {
func Success(c *fiber.Ctx, data any, args ...any) error {
var (
defaultCode = fiber.StatusOK
requestID = c.Locals(fiber.HeaderXRequestID)
startLatency = c.UserContext().Value(libcontext.ContextLatency)
latency string
)

httpCode, ok := args[0].(int)
if len(args) > 0 && ok {
txtHTTPCode := http.StatusText(defaultCode)
if txtHTTPCode != "" {
defaultCode = httpCode
}
}

start, ok := startLatency.(time.Time)
if ok {
latencyMs := float64(time.Since(start).Nanoseconds() / 1e6)
Expand Down