generated from dezh-tech/geb
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb95d53
commit 4c91d0c
Showing
59 changed files
with
966 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
return echo.NewHTTPError(http.StatusBadRequest, err) | ||
} | ||
|
||
return c.JSON(http.StatusOK, &domainhandler.DomainCreateResponse{ID: resp.ID}) | ||
} |
8 changes: 8 additions & 0 deletions
8
deliveries/http/handlers/domain_handler/dto/domain_request.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
5 changes: 5 additions & 0 deletions
5
deliveries/http/handlers/domain_handler/dto/domain_response.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package domainhandler | ||
|
||
type DomainCreateResponse struct { | ||
ID interface{} `json:"id"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
"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 { | ||
user domainhandler.Handler | ||
} | ||
|
||
func (h *HttpHandlers) Start(r *echo.Echo) { | ||
h.user.SetRoutes(r) | ||
|
||
r.GET("/swagger/*", echoSwagger.WrapHandler) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"` | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.