Skip to content

Commit

Permalink
refactor: add internal folder to manage apps and services
Browse files Browse the repository at this point in the history
BREAKING CHANGE: add internal folder to manage apps and services
  • Loading branch information
bastean committed Jul 8, 2024
1 parent f7d2b6c commit 6081521
Show file tree
Hide file tree
Showing 76 changed files with 372 additions and 303 deletions.
1 change: 1 addition & 0 deletions .air.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ testdata_dir = "testdata"
]
exclude_dir = []
include_dir = [
"internal",
"pkg"
]
include_file = []
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ test-integration: test-clean
${bash} 'go test -v -cover ./pkg/context/... -run TestIntegration.* |& tee test/report/integration.report.log'

test-acceptance-sync:
${bash} 'TEST_URL="http://localhost:8080" go test -v -cover ./pkg/cmd/... -run TestAcceptance.* |& tee test/report/acceptance.report.log'
${bash} 'TEST_URL="http://localhost:8080" go test -v -cover ./internal/app/... -run TestAcceptance.* |& tee test/report/acceptance.report.log'

test-acceptance: test-clean
TEST_SYNC="$(MAKE) test-acceptance-sync" $(MAKE) test-sync
Expand Down
61 changes: 59 additions & 2 deletions cmd/codexgo/codex.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package main

import (
"context"
"errors"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"time"

"github.com/bastean/codexgo/pkg/cmd/server"
"github.com/bastean/codexgo/internal/app/server"
"github.com/bastean/codexgo/internal/pkg/service"
"github.com/bastean/codexgo/internal/pkg/service/logger"
)

const cli = "codexgo"
Expand All @@ -25,5 +32,55 @@ func main() {

flag.Parse()

server.Run(port)
logger.Starting("services")

if err := service.Run(); err != nil {
logger.Fatal(err.Error())
}

logger.Started("services")

logger.Starting("server")

go func() {
if err := server.Run(port); err != nil {
logger.Fatal(err.Error())
}
}()

logger.Started("server")

logger.Info("server listening on :" + port)

logger.Info("press ctrl+c to exit")

shutdown := make(chan os.Signal, 1)

signal.Notify(shutdown, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)

<-shutdown

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)

defer cancel()

logger.Stopping("services")

errService := service.Stop(ctx)

logger.Stopped("services")

logger.Stopping("server")

errServer := server.Stop(ctx)

logger.Stopped("server")

if err := errors.Join(errService, errServer); err != nil {
logger.Error(err.Error())
}

<-ctx.Done()

logger.Info("exiting...")
}
2 changes: 2 additions & 0 deletions deployments/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ logs=logs

today=$(date -u +%d-%m-%Y)

mkdir -p $logs/$today

now=$(date -u +%H_%M_%S)

log=$logs/$today/$now.log
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package layout

import (
"github.com/bastean/codexgo/pkg/cmd/server/component/scripts"
"github.com/bastean/codexgo/pkg/cmd/server/component/scripts/fomantic"
"github.com/bastean/codexgo/pkg/cmd/server/component/scripts/jquery"
"github.com/bastean/codexgo/pkg/cmd/server/component/scripts/storage"
"github.com/bastean/codexgo/internal/app/server/component/scripts"
"github.com/bastean/codexgo/internal/app/server/component/scripts/fomantic"
"github.com/bastean/codexgo/internal/app/server/component/scripts/jquery"
"github.com/bastean/codexgo/internal/app/server/component/scripts/storage"
)

templ Index(headScripts scripts.Head, bodyScripts scripts.Body) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dashboard

import (
"github.com/bastean/codexgo/pkg/cmd/server/component/layout"
"github.com/bastean/codexgo/pkg/cmd/server/component/scripts"
"github.com/bastean/codexgo/pkg/cmd/server/service/user"
"github.com/bastean/codexgo/internal/app/server/component/layout"
"github.com/bastean/codexgo/internal/app/server/component/scripts"
"github.com/bastean/codexgo/internal/pkg/service/user"
)

script PageInit() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package home

import (
"github.com/bastean/codexgo/pkg/cmd/server/component/layout"
"github.com/bastean/codexgo/pkg/cmd/server/component/scripts"
"github.com/bastean/codexgo/internal/app/server/component/layout"
"github.com/bastean/codexgo/internal/app/server/component/scripts"
)

var RegisterTabTagId = "tab-register"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package page
import (
"net/http"

"github.com/bastean/codexgo/pkg/cmd/server/component/page/dashboard"
"github.com/bastean/codexgo/pkg/cmd/server/service/user"
"github.com/bastean/codexgo/pkg/cmd/server/util/errs"
"github.com/bastean/codexgo/pkg/cmd/server/util/key"
"github.com/bastean/codexgo/internal/app/server/component/page/dashboard"
"github.com/bastean/codexgo/internal/app/server/util/errs"
"github.com/bastean/codexgo/internal/app/server/util/key"
"github.com/bastean/codexgo/internal/pkg/service/user"
"github.com/gin-gonic/gin"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package page

import (
"github.com/bastean/codexgo/pkg/cmd/server/component/page/home"
"github.com/bastean/codexgo/internal/app/server/component/page/home"
"github.com/gin-gonic/gin"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package user
import (
"net/http"

"github.com/bastean/codexgo/pkg/cmd/server/service/user"
"github.com/bastean/codexgo/pkg/cmd/server/util/errs"
"github.com/bastean/codexgo/pkg/cmd/server/util/reply"
"github.com/bastean/codexgo/internal/app/server/util/errs"
"github.com/bastean/codexgo/internal/app/server/util/reply"
"github.com/bastean/codexgo/internal/pkg/service/user"
"github.com/gin-gonic/gin"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package user
import (
"net/http"

"github.com/bastean/codexgo/pkg/cmd/server/service/user"
"github.com/bastean/codexgo/pkg/cmd/server/util/errs"
"github.com/bastean/codexgo/pkg/cmd/server/util/key"
"github.com/bastean/codexgo/pkg/cmd/server/util/reply"
"github.com/bastean/codexgo/internal/app/server/util/errs"
"github.com/bastean/codexgo/internal/app/server/util/key"
"github.com/bastean/codexgo/internal/app/server/util/reply"
"github.com/bastean/codexgo/internal/pkg/service/user"
"github.com/gin-gonic/gin"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"net/http"
"time"

"github.com/bastean/codexgo/pkg/cmd/server/service/authentication/jwt"
"github.com/bastean/codexgo/pkg/cmd/server/service/user"
"github.com/bastean/codexgo/pkg/cmd/server/util/errs"
"github.com/bastean/codexgo/pkg/cmd/server/util/key"
"github.com/bastean/codexgo/pkg/cmd/server/util/reply"
"github.com/bastean/codexgo/internal/app/server/util/errs"
"github.com/bastean/codexgo/internal/app/server/util/key"
"github.com/bastean/codexgo/internal/app/server/util/reply"
"github.com/bastean/codexgo/internal/pkg/service/authentication/jwt"
"github.com/bastean/codexgo/internal/pkg/service/user"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package user
import (
"net/http"

"github.com/bastean/codexgo/pkg/cmd/server/service/user"
"github.com/bastean/codexgo/pkg/cmd/server/util/errs"
"github.com/bastean/codexgo/pkg/cmd/server/util/key"
"github.com/bastean/codexgo/pkg/cmd/server/util/reply"
"github.com/bastean/codexgo/internal/app/server/util/errs"
"github.com/bastean/codexgo/internal/app/server/util/key"
"github.com/bastean/codexgo/internal/app/server/util/reply"
"github.com/bastean/codexgo/internal/pkg/service/user"
"github.com/gin-gonic/gin"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package user
import (
"net/http"

"github.com/bastean/codexgo/pkg/cmd/server/service/user"
"github.com/bastean/codexgo/pkg/cmd/server/util/errs"
"github.com/bastean/codexgo/pkg/cmd/server/util/key"
"github.com/bastean/codexgo/internal/app/server/util/errs"
"github.com/bastean/codexgo/internal/app/server/util/key"
"github.com/bastean/codexgo/internal/pkg/service/user"
"github.com/gin-gonic/gin"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"net/http"
"strings"

"github.com/bastean/codexgo/pkg/cmd/server/service/authentication/jwt"
"github.com/bastean/codexgo/pkg/cmd/server/util/key"
"github.com/bastean/codexgo/internal/app/server/util/key"
"github.com/bastean/codexgo/internal/pkg/service/authentication/jwt"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package middleware

import (
"github.com/bastean/codexgo/pkg/cmd/server/service/env"
"github.com/bastean/codexgo/internal/pkg/service/env"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/cookie"
"github.com/gin-gonic/gin"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package middleware
import (
"net/http"

"github.com/bastean/codexgo/pkg/cmd/server/service/errors"
"github.com/bastean/codexgo/pkg/cmd/server/service/logger"
"github.com/bastean/codexgo/pkg/cmd/server/util/reply"
"github.com/bastean/codexgo/internal/app/server/util/reply"
"github.com/bastean/codexgo/internal/pkg/service/errors"
"github.com/bastean/codexgo/internal/pkg/service/logger"
"github.com/gin-gonic/gin"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package middleware
import (
"net/http"

"github.com/bastean/codexgo/pkg/cmd/server/service/logger"
"github.com/bastean/codexgo/pkg/cmd/server/util/reply"
"github.com/bastean/codexgo/internal/app/server/util/reply"
"github.com/bastean/codexgo/internal/pkg/service/logger"
"github.com/gin-gonic/gin"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package middleware
import (
"strings"

"github.com/bastean/codexgo/pkg/cmd/server/service/env"
"github.com/bastean/codexgo/internal/pkg/service/env"
"github.com/gin-contrib/secure"
"github.com/gin-gonic/gin"
)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"embed"
"net/http"

"github.com/bastean/codexgo/pkg/cmd/server/middleware"
"github.com/bastean/codexgo/internal/app/server/middleware"
"github.com/gin-gonic/gin"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package router

import (
"github.com/bastean/codexgo/pkg/cmd/server/handler/page"
"github.com/bastean/codexgo/pkg/cmd/server/handler/user"
"github.com/bastean/codexgo/pkg/cmd/server/middleware"
"github.com/bastean/codexgo/internal/app/server/handler/page"
"github.com/bastean/codexgo/internal/app/server/handler/user"
"github.com/bastean/codexgo/internal/app/server/middleware"
)

func InitRoutes() {
Expand Down
27 changes: 27 additions & 0 deletions internal/app/server/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package server

import (
"context"
"embed"
"net/http"

"github.com/bastean/codexgo/internal/app/server/router"
)

//go:embed static
var Files embed.FS

var Server *http.Server

func Run(port string) error {
Server := &http.Server{
Addr: ":" + port,
Handler: router.New(&Files),
}

return Server.ListenAndServe()
}

func Stop(ctx context.Context) error {
return Server.Shutdown(ctx)
}
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"

"github.com/bastean/codexgo/pkg/cmd/server/service/errors"
"github.com/bastean/codexgo/internal/pkg/service/errors"
)

func BindingJSON(who error, where string) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package errs
import (
"fmt"

"github.com/bastean/codexgo/pkg/cmd/server/service/errors"
"github.com/bastean/codexgo/internal/pkg/service/errors"
)

func MissingKey(what, where string) error {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package jwt

import (
"github.com/bastean/codexgo/pkg/cmd/server/service/env"
"github.com/bastean/codexgo/internal/pkg/service/env"
"github.com/bastean/codexgo/pkg/context/shared/infrastructure/authentications"
)

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6081521

Please sign in to comment.