Skip to content

Commit

Permalink
chore: init
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar committed Jan 11, 2025
1 parent bb95d53 commit 4c91d0c
Show file tree
Hide file tree
Showing 59 changed files with 966 additions and 250 deletions.
24 changes: 2 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,2 @@
# Go Echo Boilerplate

This is a golang boilerplate for projects using echo and mongo db stack on Dezh Technologies.

## Stack

* Mongo DB
* Redis
* HTTP/echo
* gRPC/google.grpc

## TODOs

- [ ] Implementing auth middleware.

## Contributions

All kind of contribution are welcome here.

## License

This repo is [unlicensed](./LICENSE).
# Panda
## NIP-05 service
6 changes: 3 additions & 3 deletions cmd/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"os/signal"
"syscall"

"github.com/dezh-tech/geb/cmd/daemon"
"github.com/dezh-tech/geb/config"
"github.com/dezh-tech/geb/pkg/logger"
"github.com/dezh-tech/panda/cmd/daemon"
"github.com/dezh-tech/panda/config"
"github.com/dezh-tech/panda/pkg/logger"
)

func HandleRun(args []string) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/commands/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import (
)

func ExitOnError(err error) {
log.Printf("immortal error: %s\n", err.Error()) //nolint
log.Printf("panda error: %s\n", err.Error()) //nolint
os.Exit(1)
}
24 changes: 12 additions & 12 deletions cmd/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package daemon
import (
"time"

"github.com/dezh-tech/geb/config"
"github.com/dezh-tech/geb/delivery/grpc"
"github.com/dezh-tech/geb/delivery/http"
"github.com/dezh-tech/geb/infrastructure/database"
grpcclient "github.com/dezh-tech/geb/infrastructure/grpc_client"
"github.com/dezh-tech/geb/infrastructure/redis"
"github.com/dezh-tech/geb/pkg/logger"
userrepo "github.com/dezh-tech/geb/repository/user"
usersrv "github.com/dezh-tech/geb/service/user"
"github.com/dezh-tech/panda/config"
"github.com/dezh-tech/panda/deliveries/grpc"
"github.com/dezh-tech/panda/deliveries/http"
"github.com/dezh-tech/panda/infrastructures/database"
grpcClient "github.com/dezh-tech/panda/infrastructures/grpc_client"
"github.com/dezh-tech/panda/infrastructures/redis"
"github.com/dezh-tech/panda/pkg/logger"
domainRepo "github.com/dezh-tech/panda/repositories/domain"
domainService "github.com/dezh-tech/panda/services/domain"
)

type Daemon struct {
Expand All @@ -33,14 +33,14 @@ func New(cfg *config.Config) (*Daemon, error) {
return nil, err
}

_, err = grpcclient.New(cfg.GRPCClient.Endpoint)
_, err = grpcClient.New(cfg.GRPCClient.Endpoint)
if err != nil {
return nil, err
}

userRepo := userrepo.New(db)
userRepo := domainRepo.New(db)

hs := http.New(cfg.HTTPServer, usersrv.New(userRepo))
hs := http.New(cfg.HTTPServer, domainService.New(userRepo))
gs := grpc.New(&cfg.GRPCServer, r, db, time.Now())

return &Daemon{
Expand Down
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"os"

goginboilerplate "github.com/dezh-tech/geb"
"github.com/dezh-tech/geb/cmd/commands"
goginboilerplate "github.com/dezh-tech/panda"
"github.com/dezh-tech/panda/cmd/commands"
)

func main() {
Expand Down
12 changes: 6 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package config
import (
"os"

"github.com/dezh-tech/geb/delivery/grpc"
"github.com/dezh-tech/geb/delivery/http"
"github.com/dezh-tech/geb/infrastructure/database"
grpcclient "github.com/dezh-tech/geb/infrastructure/grpc_client"
"github.com/dezh-tech/geb/infrastructure/redis"
"github.com/dezh-tech/geb/pkg/logger"
"github.com/dezh-tech/panda/deliveries/grpc"
"github.com/dezh-tech/panda/deliveries/http"
"github.com/dezh-tech/panda/infrastructures/database"
grpcclient "github.com/dezh-tech/panda/infrastructures/grpc_client"
"github.com/dezh-tech/panda/infrastructures/redis"
"github.com/dezh-tech/panda/pkg/logger"
"github.com/joho/godotenv"
"gopkg.in/yaml.v3"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions delivery/grpc/health.go → deliveries/grpc/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"context"
"time"

goginboilerplate "github.com/dezh-tech/geb"
pb "github.com/dezh-tech/geb/delivery/grpc/gen"
goginboilerplate "github.com/dezh-tech/panda"
pb "github.com/dezh-tech/panda/deliveries/grpc/gen"
)

type healthServer struct {
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions delivery/grpc/server.go → deliveries/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"strconv"
"time"

pb "github.com/dezh-tech/geb/delivery/grpc/gen"
"github.com/dezh-tech/geb/infrastructure/database"
"github.com/dezh-tech/geb/infrastructure/redis"
pb "github.com/dezh-tech/panda/deliveries/grpc/gen"
"github.com/dezh-tech/panda/infrastructures/database"
"github.com/dezh-tech/panda/infrastructures/redis"
"google.golang.org/grpc"
)

Expand Down
File renamed without changes.
File renamed without changes.
49 changes: 49 additions & 0 deletions deliveries/http/handlers/domain_handler/domain_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package domainhandler

import (
"fmt"
"net/http"

domainhandler "github.com/dezh-tech/panda/deliveries/http/handlers/domain_handler/dto"
"github.com/dezh-tech/panda/pkg/validator"
domainService "github.com/dezh-tech/panda/services/domain"
"github.com/labstack/echo/v4"
)

// CreateDomain creates a new domain.
//
// @Summary Create a new domain
// @Description Accepts a JSON payload to create a new domain with the specified attributes.
// @Tags domain
// @Accept json
// @Produce json
// @Param domain body domainhandler.DomainCreateRequest true "Domain creation payload"
// @Success 200 {object} domainhandler.DomainCreateResponse "Domain created successfully"
// @Failure 400 {object} map[string]string "Bad Request - Invalid input"
// @Failure 500 {object} map[string]string "Internal Server Error"
// @Router /domains [post]
func (h Handler) domainCreate(c echo.Context) error {
req := new(domainhandler.DomainCreateRequest)
if err := c.Bind(req); err != nil {
return err
}

v := validator.NewValidator()
validationErrors := v.Validate(req)
if validationErrors != nil {
return echo.NewHTTPError(http.StatusBadRequest, &validator.Varror{ValidationErrors: validationErrors})
}

resp, err := h.domainSvc.Create(domainService.DomainInsertArgs{
Domain: req.Domain,
BasePricePerIdentifier: req.BasePricePerIdentifier,
DefaultTTL: req.DefaultTTL,
Status: req.Status,
})
if err != nil {
fmt.Println(err)

Check failure on line 44 in deliveries/http/handlers/domain_handler/domain_create.go

View workflow job for this annotation

GitHub Actions / lint

use of `fmt.Println` forbidden by pattern `^(fmt\.Print(|f|ln)|print|println)$` (forbidigo)
return echo.NewHTTPError(http.StatusBadRequest, err)
}

return c.JSON(http.StatusOK, &domainhandler.DomainCreateResponse{ID: resp.ID})
}
8 changes: 8 additions & 0 deletions deliveries/http/handlers/domain_handler/dto/domain_request.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package domainhandler

type DomainCreateRequest struct {
Domain string `json:"domain" validate:"required,hostname" form:"domain" query:"domain"`
BasePricePerIdentifier uint `json:"base_price_per_identifier" validate:"required,min=1" form:"base_price_per_identifier" query:"base_price_per_identifier"`
DefaultTTL uint32 `json:"default_ttl" validate:"required,min=1" form:"default_ttl" query:"default_ttl"`
Status string `json:"status" validate:"required,oneof=active inactive" form:"status" query:"status"`
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package domainhandler

type DomainCreateResponse struct {
ID interface{} `json:"id"`
}
13 changes: 13 additions & 0 deletions deliveries/http/handlers/domain_handler/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package domainhandler

import domainService "github.com/dezh-tech/panda/services/domain"

type Handler struct {
domainSvc domainService.DomainService
}

func New(domainSvc domainService.DomainService) Handler {
return Handler{
domainSvc: domainSvc,
}
}
11 changes: 11 additions & 0 deletions deliveries/http/handlers/domain_handler/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package domainhandler

import (
"github.com/labstack/echo/v4"
)

func (h Handler) SetRoutes(e *echo.Echo) {
userGroup := e.Group("/domains")

userGroup.POST("", h.domainCreate)
}
33 changes: 33 additions & 0 deletions deliveries/http/http_handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package http

import (
domainhandler "github.com/dezh-tech/panda/deliveries/http/handlers/domain_handler"
_ "github.com/dezh-tech/panda/docs"

Check failure on line 5 in deliveries/http/http_handlers.go

View workflow job for this annotation

GitHub Actions / lint

blank-imports: a blank import should be only in a main or test package, or have a comment justifying it (revive)
"github.com/labstack/echo/v4"
echoSwagger "github.com/swaggo/echo-swagger"
)

// @title Panda Swagger
// @version 1.0
// @description This is a sample server Petstore server.
// @termsOfService http://swagger.io/terms/

// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io

// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html

// @host localhost:8080
// @BasePath /

type HttpHandlers struct {

Check failure on line 25 in deliveries/http/http_handlers.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: type HttpHandlers should be HTTPHandlers (revive)
user domainhandler.Handler
}

func (h *HttpHandlers) Start(r *echo.Echo) {
h.user.SetRoutes(r)

r.GET("/swagger/*", echoSwagger.WrapHandler)
}
45 changes: 45 additions & 0 deletions deliveries/http/http_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package http

import (
"fmt"

domainhandler "github.com/dezh-tech/panda/deliveries/http/handlers/domain_handler"
domainService "github.com/dezh-tech/panda/services/domain"
"github.com/labstack/echo/v4"
)

type Server struct {
Router *echo.Echo
config Config
handlers HttpHandlers
}

func New(config Config, userSvc domainService.DomainService) Server {
return Server{
Router: echo.New(),
config: config,

handlers: HttpHandlers{
user: domainhandler.New(userSvc),
},
}
}

func (s Server) Start() error {
s.handlers.Start(s.Router)

address := fmt.Sprintf(":%d", s.config.Port)
if err := s.Router.Start(address); err != nil {
return err
}

return nil
}

func (s Server) Stop() error {
if err := s.Router.Close(); err != nil {
return err
}

return nil
}
File renamed without changes.
7 changes: 7 additions & 0 deletions deliveries/http/response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package http

type Response struct {
Success bool `json:"success"`
Message string `json:"message"`
Data interface{} `json:"data"`
}
42 changes: 0 additions & 42 deletions delivery/http/server.go

This file was deleted.

13 changes: 0 additions & 13 deletions delivery/http/user_handler/handler.go

This file was deleted.

19 changes: 0 additions & 19 deletions delivery/http/user_handler/profile.go

This file was deleted.

Loading

0 comments on commit 4c91d0c

Please sign in to comment.