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
10 changes: 5 additions & 5 deletions api/users/create_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"errors"
"fmt"
"github.com/gocanto/blog/env"
"github.com/gocanto/blog/webkit"
"github.com/gocanto/blog/webkit/media"
"github.com/gocanto/blog/webkit/request"
"github.com/gocanto/blog/webkit/response"
"github.com/gocanto/blog/pkg"
"github.com/gocanto/blog/pkg/media"
"github.com/gocanto/blog/pkg/request"
"github.com/gocanto/blog/pkg/response"
"io"
"mime/multipart"
"net/http"
Expand Down Expand Up @@ -76,7 +76,7 @@ func (handler UserHandler) Create(w http.ResponseWriter, r *http.Request) *respo
},
}

return webkit.SendJSON(w, http.StatusCreated, payload)
return pkg.SendJSON(w, http.StatusCreated, payload)
}

func extractData[T media.MultipartFormInterface](reader *multipart.Reader, data T) error {
Expand Down
2 changes: 1 addition & 1 deletion api/users/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package users
import (
"fmt"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/webkit/gorm"
"github.com/gocanto/blog/pkg/gorm"
"github.com/google/uuid"
"strings"
"time"
Expand Down
4 changes: 2 additions & 2 deletions api/users/users_schema.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package users

import (
"github.com/gocanto/blog/webkit"
"github.com/gocanto/blog/pkg"
)

type UserHandler struct {
Validator *webkit.Validator
Validator *pkg.Validator
Repository *Repository
}
14 changes: 7 additions & 7 deletions bootstrap/app.go → boost/app.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package bootstrap
package boost

import (
"github.com/gocanto/blog/api/users"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/env"
"github.com/gocanto/blog/webkit"
"github.com/gocanto/blog/webkit/llogs"
"github.com/gocanto/blog/webkit/middleware"
"github.com/gocanto/blog/pkg"
"github.com/gocanto/blog/pkg/llogs"
"github.com/gocanto/blog/pkg/middleware"
"net/http"
)

type App struct {
Validator *webkit.Validator `validate:"required"`
Validator *pkg.Validator `validate:"required"`
Logs *llogs.Driver `validate:"required"`
DbConnection *database.Connection `validate:"required"`
AdminUser *users.AdminUser `validate:"required"`
Env *env.Environment `validate:"required"`
Mux *http.ServeMux `validate:"required"`
Sentry *webkit.Sentry `validate:"required"`
Sentry *pkg.Sentry `validate:"required"`
}

func MakeApp(mux *http.ServeMux, app *App) *App {
Expand All @@ -36,7 +36,7 @@ func (app App) RegisterUsers() {
Validator: app.Validator,
}

app.Mux.HandleFunc("POST /users", webkit.CreateHandle(
app.Mux.HandleFunc("POST /users", pkg.CreateHandle(
stack.Push(
handler.Create,
stack.AdminUser,
Expand Down
12 changes: 6 additions & 6 deletions bootstrap/boostrap.go → boost/boost.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package bootstrap
package boost

import (
"github.com/getsentry/sentry-go"
sentryhttp "github.com/getsentry/sentry-go/http"
"github.com/gocanto/blog/api/users"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/env"
"github.com/gocanto/blog/webkit"
"github.com/gocanto/blog/webkit/llogs"
"github.com/gocanto/blog/pkg"
"github.com/gocanto/blog/pkg/llogs"
"log"
"strconv"
"strings"
"time"
)

func MakeSentry(env *env.Environment) *webkit.Sentry {
func MakeSentry(env *env.Environment) *pkg.Sentry {
cOptions := sentry.ClientOptions{
Dsn: env.Sentry.DSN,
Debug: true,
Expand All @@ -29,7 +29,7 @@ func MakeSentry(env *env.Environment) *webkit.Sentry {
options := sentryhttp.Options{}
handler := sentryhttp.New(options)

return &webkit.Sentry{
return &pkg.Sentry{
Handler: handler,
Options: &options,
Env: env,
Expand Down Expand Up @@ -63,7 +63,7 @@ func MakeAdminUser(env *env.Environment) *users.AdminUser {
}
}

func MakeEnv(values map[string]string, validate *webkit.Validator) *env.Environment {
func MakeEnv(values map[string]string, validate *pkg.Validator) *env.Environment {
errorSufix := "Environment: "

port, _ := strconv.Atoi(values["ENV_DB_PORT"])
Expand Down
6 changes: 3 additions & 3 deletions bootstrap/spark.go → boost/spark.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package bootstrap
package boost

import (
"github.com/gocanto/blog/env"
"github.com/gocanto/blog/webkit"
"github.com/gocanto/blog/pkg"
"github.com/joho/godotenv"
)

func Spark(envPath string) (*env.Environment, *webkit.Validator) {
func Spark(envPath string) (*env.Environment, *pkg.Validator) {
validate := GetDefaultValidate()

envMap, err := godotenv.Read(envPath)
Expand Down
12 changes: 12 additions & 0 deletions boost/validate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package boost

import (
baseValidator "github.com/go-playground/validator/v10"
"github.com/gocanto/blog/pkg"
)

func GetDefaultValidate() *pkg.Validator {
return pkg.MakeValidatorFrom(baseValidator.New(
baseValidator.WithRequiredStructEnabled(),
))
}
12 changes: 0 additions & 12 deletions bootstrap/validate.go

This file was deleted.

2 changes: 1 addition & 1 deletion config/makefile/env.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ___ENV___ROOT__PATH := $(shell pwd)
___ENV___FILE_NAME := ".env"
___ENV___EXAMPLE_FILE_NAME := ".env.example"

include $(___ENV___ROOT__PATH)/.env
-include $(___ENV___ROOT__PATH)/.env

env\:init:
@if [ ! -f $(___ENV___FILE_NAME) ]; then \
Expand Down
10 changes: 5 additions & 5 deletions database/seeder/main.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package main

import (
"github.com/gocanto/blog/bootstrap"
"github.com/gocanto/blog/boost"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/database/seeder/seeds"
"github.com/gocanto/blog/env"
"github.com/gocanto/blog/webkit/cli"
"github.com/gocanto/blog/pkg/cli"
"sync"
"time"
)

var environment *env.Environment

func init() {
secrets, _ := bootstrap.Spark("./.env")
secrets, _ := boost.Spark("./.env")

environment = secrets
}

func main() {
dbConnection := bootstrap.MakeDbConnection(environment)
logs := bootstrap.MakeLogs(environment)
dbConnection := boost.MakeDbConnection(environment)
logs := boost.MakeLogs(environment)

defer (*logs).Close()
defer (*dbConnection).Close()
Expand Down
2 changes: 1 addition & 1 deletion database/seeder/seeds/categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package seeds
import (
"fmt"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/webkit/gorm"
"github.com/gocanto/blog/pkg/gorm"
"github.com/google/uuid"
)

Expand Down
2 changes: 1 addition & 1 deletion database/seeder/seeds/likes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package seeds
import (
"fmt"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/webkit/gorm"
"github.com/gocanto/blog/pkg/gorm"
"github.com/google/uuid"
)

Expand Down
2 changes: 1 addition & 1 deletion database/seeder/seeds/newsletters.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package seeds
import (
"fmt"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/webkit/gorm"
"github.com/gocanto/blog/pkg/gorm"
"time"
)

Expand Down
2 changes: 1 addition & 1 deletion database/seeder/seeds/post_categories.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package seeds
import (
"fmt"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/webkit/gorm"
"github.com/gocanto/blog/pkg/gorm"
)

type PostCategoriesSeed struct {
Expand Down
2 changes: 1 addition & 1 deletion database/seeder/seeds/post_tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package seeds
import (
"fmt"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/webkit/gorm"
"github.com/gocanto/blog/pkg/gorm"
)

type PostTagsSeed struct {
Expand Down
2 changes: 1 addition & 1 deletion database/seeder/seeds/post_views.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package seeds
import (
"fmt"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/webkit/gorm"
"github.com/gocanto/blog/pkg/gorm"
)

type PostViewsSeed struct {
Expand Down
2 changes: 1 addition & 1 deletion database/seeder/seeds/posts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package seeds
import (
"fmt"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/webkit/gorm"
"github.com/gocanto/blog/pkg/gorm"
"github.com/google/uuid"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion database/seeder/seeds/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package seeds
import (
"fmt"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/webkit/gorm"
"github.com/gocanto/blog/pkg/gorm"
"github.com/google/uuid"
)

Expand Down
2 changes: 1 addition & 1 deletion database/seeder/seeds/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"github.com/gocanto/blog/api/users"
"github.com/gocanto/blog/database"
"github.com/gocanto/blog/webkit/gorm"
"github.com/gocanto/blog/pkg/gorm"
"github.com/google/uuid"
"strings"
"time"
Expand Down
18 changes: 9 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
package main

import (
"github.com/gocanto/blog/bootstrap"
"github.com/gocanto/blog/boost"
"github.com/gocanto/blog/env"
"github.com/gocanto/blog/webkit"
"github.com/gocanto/blog/pkg"
_ "github.com/lib/pq"
"log/slog"
"net/http"
)

var environment *env.Environment
var validator *webkit.Validator
var validator *pkg.Validator

func init() {
secrets, validate := bootstrap.Spark("./.env")
secrets, validate := boost.Spark("./.env")

environment = secrets
validator = validate
}

func main() {
dbConnection := bootstrap.MakeDbConnection(environment)
logs := bootstrap.MakeLogs(environment)
adminUser := bootstrap.MakeAdminUser(environment)
localSentry := bootstrap.MakeSentry(environment)
dbConnection := boost.MakeDbConnection(environment)
logs := boost.MakeLogs(environment)
adminUser := boost.MakeAdminUser(environment)
localSentry := boost.MakeSentry(environment)

defer (*logs).Close()
defer (*dbConnection).Close()

mux := http.NewServeMux()

app := bootstrap.MakeApp(mux, &bootstrap.App{
app := boost.MakeApp(mux, &boost.App{
Validator: validator,
Logs: logs,
DbConnection: dbConnection,
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions webkit/handler.go → pkg/handler.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package webkit
package pkg

import (
"encoding/json"
"github.com/gocanto/blog/webkit/response"
"github.com/gocanto/blog/pkg/response"
"log/slog"
"net/http"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion webkit/media/support.go → pkg/media/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func GetStorageDir() string {

if err != nil {
// Handle the error appropriately.
// Path default to relative path if getting WD fails
// Path default to a relative path if getting WD fails
return "./" + folder
}

Expand Down
Loading
Loading