Compare commits

..

5 Commits

Author SHA1 Message Date
420515f5b6 make error message more human readable 2024-07-16 18:19:49 +02:00
5dcd27e8b8 Update traefik router tag 2024-07-15 20:10:06 +02:00
0333862e3c error print fix 2024-05-30 17:19:16 +02:00
081e1edd24 go.mod update priv git url 2024-05-30 17:16:39 +02:00
c454307d56 consul fixes 2024-04-19 19:17:09 +02:00
6 changed files with 49 additions and 9 deletions

View File

@@ -3,7 +3,7 @@ package api
import (
"fmt"
def "git.pbiernat.dev/egommerce/api-entities/http"
def "git.pbiernat.io/egommerce/api-entities/http"
"github.com/go-redis/redis/v8"
)

View File

@@ -3,7 +3,7 @@ package api
import (
"fmt"
def "git.pbiernat.dev/egommerce/api-entities/http"
def "git.pbiernat.io/egommerce/api-entities/http"
"github.com/go-redis/redis/v8"
)

View File

@@ -3,6 +3,7 @@ package config
import (
"os"
"github.com/gofiber/fiber/v2/log"
"github.com/joho/godotenv"
)
@@ -15,7 +16,7 @@ func init() {
func GetEnv(name string, defVal string) string {
env := os.Getenv(name)
if env == "" {
return defVal
log.Panicf("Missing %s env variable", name)
}
return env

View File

@@ -6,7 +6,7 @@ import (
"strconv"
"time"
"git.pbiernat.dev/egommerce/go-api-pkg/config"
"git.pbiernat.io/egommerce/go-api-pkg/config"
consul "github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/connect"
)
@@ -113,7 +113,7 @@ func (s *Service) RegisterHealthChecks() {
ticker := time.NewTicker(interval)
for range ticker.C {
if _, err := s.healthCheck(); err != nil {
fmt.Printf("TTL Error #: %v\n", err)
fmt.Printf("HealthCheck endpoint not available #: %v\n", err)
}
}
}()
@@ -178,9 +178,10 @@ func (s *Service) healthCheck() (bool, error) {
func (s *Service) getTags() []string {
tags := []string{
"traefik.enable=true",
"traefik.http.routers." + s.Name + ".rule=PathPrefix(`" + s.pathPrefix + "`)",
// "traefik.http.routers." + s.Name + ".rule=PathPrefix(`" + s.pathPrefix + "`)",
"traefik.http.routers." + s.Name + ".rule=Host(`" + s.domain + "`)",
"traefik.http.routers." + s.Name + ".entryPoints=https",
"traefik.http.routers." + s.Name + ".tls=true",
// "traefik.http.routers." + s.Name + ".tls=true",
"traefik.http.routers." + s.Name + ".service=" + s.Name,
"traefik.http.routers." + s.Name + ".middlewares=auth_" + s.Name + ",requestid_" + s.Name + ",stripprefix_" + s.Name,
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=http",

4
go.mod
View File

@@ -1,9 +1,9 @@
module git.pbiernat.dev/egommerce/go-api-pkg
module git.pbiernat.io/egommerce/go-api-pkg
go 1.18
require (
git.pbiernat.dev/egommerce/api-entities v0.0.26
git.pbiernat.io/egommerce/api-entities v0.0.26
github.com/fluent/fluent-logger-golang v1.9.0
github.com/go-redis/redis/v8 v8.11.5
github.com/hashicorp/consul v1.16.0

38
redis/cache.go Normal file
View File

@@ -0,0 +1,38 @@
package redis
// import (
// "context"
// "strconv"
// "time"
// "github.com/go-redis/redis/v8"
// )
// func NewCache(host string, port int, password string) *redis.Client {
// redis := redis.NewClient(&redis.Options{
// Addr: host + ":" + strconv.Itoa(port),
// Password: password,
// DB: 0,
// })
// defer redis.Close()
// return redis
// }
// func Get(ctx context.Context, key string) (float64, error) {
// // ctx := context.Background() // FIXME
// price, err := s.cache.Get(ctx, key).Float64()
// if err != nil {
// s.log.Log("cache read error(key not exists): %#v", err)
// return 0, err
// }
// return price, nil
// }
// func Set(ctx context.Context, key string, value any, exp time.Duration) error {
// // ctx := context.Background() // FIXME
// s.cache.Set(ctx, key, value, exp)
// return nil
// }