feat: testing
This commit is contained in:
@@ -6,7 +6,7 @@ vars:
|
|||||||
GO_CMD:
|
GO_CMD:
|
||||||
sh: command -v go >/dev/null 2>&1 && echo "go"
|
sh: command -v go >/dev/null 2>&1 && echo "go"
|
||||||
|
|
||||||
GO_FLAGS: "-ldflags=-s -w -trimpath"
|
GO_FLAGS: '-ldflags="-s -w"'
|
||||||
|
|
||||||
TAILWIND_CMD: "tailwindcss"
|
TAILWIND_CMD: "tailwindcss"
|
||||||
|
|
||||||
@@ -18,6 +18,8 @@ tasks:
|
|||||||
- task --parallel tailwind templ
|
- task --parallel tailwind templ
|
||||||
|
|
||||||
run:
|
run:
|
||||||
|
env:
|
||||||
|
STRAPI_TOKEN: 918aad014c203e302ee185628a0591b1bc875bd999cb9cd7b9c81fac68f275cda75ea806c7ea7b352253a680838887b65a09a9904c6a140bfb3b794d19083c2659d5ad210bca8044436d67b3f6db4d7262168f66b5748b367e8d3239167c185f3b0f0932f8e10800bfb6ad0355ec7d5ca1edbe0d06814bee0a92ab7ebcef3022
|
||||||
desc: Build and run go server binary
|
desc: Build and run go server binary
|
||||||
deps: [build, build-css]
|
deps: [build, build-css]
|
||||||
cmds:
|
cmds:
|
||||||
@@ -34,7 +36,7 @@ tasks:
|
|||||||
generates:
|
generates:
|
||||||
- dist/server
|
- dist/server
|
||||||
cmds:
|
cmds:
|
||||||
- "{{ .GO_CMD }} build {{ .PROD_FLAGS }} -o dist/server cmd/main.go"
|
- "{{ .GO_CMD }} build {{ .GO_FLAGS }} -o dist/server cmd/main.go"
|
||||||
|
|
||||||
build-queries:
|
build-queries:
|
||||||
desc: Builds GraphQL queries
|
desc: Builds GraphQL queries
|
||||||
|
|||||||
30
cmd/main.go
30
cmd/main.go
@@ -1,11 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"blog/internal/database"
|
|
||||||
"blog/internal/config"
|
|
||||||
"github.com/charmbracelet/log"
|
|
||||||
"blog/internal/cache"
|
"blog/internal/cache"
|
||||||
|
"blog/internal/config"
|
||||||
|
"blog/internal/database"
|
||||||
"blog/internal/services"
|
"blog/internal/services"
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -26,8 +29,25 @@ func main() {
|
|||||||
|
|
||||||
// Create Redis caches
|
// Create Redis caches
|
||||||
strapi_cache := cache.CreateCache(server_config.RedisHost, server_config.RedisPort, 0)
|
strapi_cache := cache.CreateCache(server_config.RedisHost, server_config.RedisPort, 0)
|
||||||
analytics_cache := cache.CreateCache(server_config.RedisHost, server_config.RedisPort, 1)
|
// analytics_cache := cache.CreateCache(server_config.RedisHost, server_config.RedisPort, 1)
|
||||||
|
|
||||||
// Create Strapi service
|
// Create Strapi service
|
||||||
strapi_service := services.NewStrapiService(server_config.StrapiHost, server_config.StrapiApiKey, strapi_cache)
|
strapi_service := services.NewStrapiService(server_config.StrapiEndpoint+"/graphql", server_config.StrapiToken, strapi_cache)
|
||||||
|
|
||||||
|
// Strapi logger
|
||||||
|
strapi_logger := log.NewWithOptions(os.Stderr, log.Options{
|
||||||
|
ReportTimestamp: true,
|
||||||
|
Prefix: "STRAPI",
|
||||||
|
})
|
||||||
|
|
||||||
|
// Test strapi get
|
||||||
|
posts, err := strapi_service.GetFeaturedPosts(context.Background(), 10, 1)
|
||||||
|
if err != nil {
|
||||||
|
strapi_logger.Error(err)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
post := posts[0]
|
||||||
|
|
||||||
|
strapi_logger.Info(post)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import (
|
|||||||
type ServerConfig struct {
|
type ServerConfig struct {
|
||||||
Host string
|
Host string
|
||||||
Port int
|
Port int
|
||||||
StrapiHost string
|
StrapiEndpoint string
|
||||||
RedisHost string
|
RedisHost string
|
||||||
RedisPort int
|
RedisPort int
|
||||||
StrapiApiKey string
|
StrapiToken string
|
||||||
CacheTTL int
|
CacheTTL int
|
||||||
EchoMode string
|
EchoMode string
|
||||||
}
|
}
|
||||||
@@ -23,8 +23,8 @@ func NewServerConfig() *ServerConfig {
|
|||||||
func (c *ServerConfig) LoadConfig() {
|
func (c *ServerConfig) LoadConfig() {
|
||||||
c.Host = env.GetString("HOST", "0.0.0.0")
|
c.Host = env.GetString("HOST", "0.0.0.0")
|
||||||
c.Port = env.GetInt("PORT", 3000)
|
c.Port = env.GetInt("PORT", 3000)
|
||||||
c.StrapiHost = env.GetString("STRAPI_HOST", "https://strapi.darwincereska.dev")
|
c.StrapiEndpoint = env.GetString("STRAPI_ENDPOINT", "https://strapi.darwincereska.dev")
|
||||||
c.StrapiApiKey = env.GetString("STRAPI_API_KEY", "")
|
c.StrapiToken = env.GetString("STRAPI_TOKEN", "")
|
||||||
c.RedisHost = env.GetString("REDIS_HOST", "localhost")
|
c.RedisHost = env.GetString("REDIS_HOST", "localhost")
|
||||||
c.RedisPort = env.GetInt("REDIS_PORT", 6379)
|
c.RedisPort = env.GetInt("REDIS_PORT", 6379)
|
||||||
c.CacheTTL = env.GetInt("CACHE_TTL", 3600)
|
c.CacheTTL = env.GetInt("CACHE_TTL", 3600)
|
||||||
@@ -34,7 +34,7 @@ func (c *ServerConfig) LoadConfig() {
|
|||||||
log.Info("Host", "host", c.Host)
|
log.Info("Host", "host", c.Host)
|
||||||
log.Info("Port", "port", c.Port)
|
log.Info("Port", "port", c.Port)
|
||||||
log.Info("Redis Host", "host", c.RedisHost)
|
log.Info("Redis Host", "host", c.RedisHost)
|
||||||
log.Info("Strapi URL", "host", c.StrapiHost)
|
log.Info("Strapi URL", "host", c.StrapiEndpoint)
|
||||||
log.Info("Echo Mode", "mode", c.EchoMode)
|
log.Info("Echo Mode", "mode", c.EchoMode)
|
||||||
log.Info("Cache TTL", "ttl", c.CacheTTL)
|
log.Info("Cache TTL", "ttl", c.CacheTTL)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user