forked from ebhomengo/niki
fix: rebase
This commit is contained in:
parent
620db23582
commit
4185ef594b
|
@ -16,7 +16,7 @@ import (
|
||||||
// @Param Request body adminserviceparam.LoginWithPhoneNumberRequest true "Admin login request body"
|
// @Param Request body adminserviceparam.LoginWithPhoneNumberRequest true "Admin login request body"
|
||||||
// @Success 200 {object} adminserviceparam.LoginWithPhoneNumberResponse
|
// @Success 200 {object} adminserviceparam.LoginWithPhoneNumberResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Router /admins/login-by-phone [post]
|
// @Router /admins/login-by-phone [post].
|
||||||
func (h Handler) LoginByPhoneNumber(c echo.Context) error {
|
func (h Handler) LoginByPhoneNumber(c echo.Context) error {
|
||||||
var req adminserviceparam.LoginWithPhoneNumberRequest
|
var req adminserviceparam.LoginWithPhoneNumberRequest
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
// @Success 200 {object} adminserviceparam.RegisterResponse
|
// @Success 200 {object} adminserviceparam.RegisterResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerAdmin
|
// @Security AuthBearerAdmin
|
||||||
// @Router /admins/register [post]
|
// @Router /admins/register [post].
|
||||||
func (h Handler) Register(c echo.Context) error {
|
func (h Handler) Register(c echo.Context) error {
|
||||||
var req adminserviceparam.RegisterRequest
|
var req adminserviceparam.RegisterRequest
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
// @Success 200 {object} param.KindBoxReqAcceptResponse
|
// @Success 200 {object} param.KindBoxReqAcceptResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerAdmin
|
// @Security AuthBearerAdmin
|
||||||
// @Router /admin/kindboxreqs/accept-kind-box-req/{id} [patch]
|
// @Router /admin/kindboxreqs/accept-kind-box-req/{id} [patch].
|
||||||
func (h Handler) Accept(c echo.Context) error {
|
func (h Handler) Accept(c echo.Context) error {
|
||||||
var req param.KindBoxReqAcceptRequest
|
var req param.KindBoxReqAcceptRequest
|
||||||
if bErr := c.Bind(&req); bErr != nil {
|
if bErr := c.Bind(&req); bErr != nil {
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
// @Success 200 {object} param.AssignSenderResponse
|
// @Success 200 {object} param.AssignSenderResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerAdmin
|
// @Security AuthBearerAdmin
|
||||||
// @Router /admin/kindboxreqs/assign-sender-agent/{id} [patch]
|
// @Router /admin/kindboxreqs/assign-sender-agent/{id} [patch].
|
||||||
func (h Handler) AssignSenderAgent(c echo.Context) error {
|
func (h Handler) AssignSenderAgent(c echo.Context) error {
|
||||||
var req param.AssignSenderRequest
|
var req param.AssignSenderRequest
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
// @Success 200 {object} param.DeliverKindBoxReqResponse
|
// @Success 200 {object} param.DeliverKindBoxReqResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerAdmin
|
// @Security AuthBearerAdmin
|
||||||
// @Router /admin/kindboxreqs/deliver-kind-box-req/{id} [patch]
|
// @Router /admin/kindboxreqs/deliver-kind-box-req/{id} [patch].
|
||||||
func (h Handler) Deliver(c echo.Context) error {
|
func (h Handler) Deliver(c echo.Context) error {
|
||||||
var req param.DeliverKindBoxReqRequest
|
var req param.DeliverKindBoxReqRequest
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
// @Success 200 {object} param.KindBoxReqGetAllResponse
|
// @Success 200 {object} param.KindBoxReqGetAllResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerAdmin
|
// @Security AuthBearerAdmin
|
||||||
// @Router /admin/kindboxreqs [get]
|
// @Router /admin/kindboxreqs [get].
|
||||||
func (h Handler) GetAll(c echo.Context) error {
|
func (h Handler) GetAll(c echo.Context) error {
|
||||||
var req param.KindBoxReqGetAllRequest
|
var req param.KindBoxReqGetAllRequest
|
||||||
if bErr := c.Bind(&req); bErr != nil {
|
if bErr := c.Bind(&req); bErr != nil {
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
// @Success 200 {object} param.KindBoxReqRejectResponse
|
// @Success 200 {object} param.KindBoxReqRejectResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerAdmin
|
// @Security AuthBearerAdmin
|
||||||
// @Router /admin/kindboxreqs/reject-kind-box-req/{id} [patch]
|
// @Router /admin/kindboxreqs/reject-kind-box-req/{id} [patch].
|
||||||
func (h Handler) Reject(c echo.Context) error {
|
func (h Handler) Reject(c echo.Context) error {
|
||||||
var req param.KindBoxReqRejectRequest
|
var req param.KindBoxReqRejectRequest
|
||||||
if bErr := c.Bind(&req); bErr != nil {
|
if bErr := c.Bind(&req); bErr != nil {
|
||||||
|
|
|
@ -10,6 +10,7 @@ func (h Handler) SetRoutes(e *echo.Echo) {
|
||||||
r := e.Group("/admin/kindboxreqs")
|
r := e.Group("/admin/kindboxreqs")
|
||||||
|
|
||||||
r.Use(middleware.Auth(h.authSvc, h.authConfig))
|
r.Use(middleware.Auth(h.authSvc, h.authConfig))
|
||||||
|
r.POST("", h.AddKindBoxReq, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAddPermission))
|
||||||
r.PATCH("/accept-kind-box-req/:id", h.Accept, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAcceptPermission))
|
r.PATCH("/accept-kind-box-req/:id", h.Accept, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqAcceptPermission))
|
||||||
r.PATCH("/reject-kind-box-req/:id", h.Reject, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqRejectPermission))
|
r.PATCH("/reject-kind-box-req/:id", h.Reject, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqRejectPermission))
|
||||||
r.PATCH("/deliver-kind-box-req/:id", h.Deliver, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqDeliverPermission))
|
r.PATCH("/deliver-kind-box-req/:id", h.Deliver, middleware.AdminAuthorization(h.adminAuthorizeSvc, entity.AdminKindBoxReqDeliverPermission))
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
// @Success 201 {object} param.BenefactorAddAddressResponse
|
// @Success 201 {object} param.BenefactorAddAddressResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerBenefactor
|
// @Security AuthBearerBenefactor
|
||||||
// @Router /address/ [post]
|
// @Router /address/ [post].
|
||||||
func (h Handler) AddAddress(c echo.Context) error {
|
func (h Handler) AddAddress(c echo.Context) error {
|
||||||
req := param.BenefactorAddAddressRequest{}
|
req := param.BenefactorAddAddressRequest{}
|
||||||
if bErr := c.Bind(&req); bErr != nil {
|
if bErr := c.Bind(&req); bErr != nil {
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
// @Success 200 {object} param.GetAddressResponse
|
// @Success 200 {object} param.GetAddressResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerBenefactor
|
// @Security AuthBearerBenefactor
|
||||||
// @Router /address/{id} [get]
|
// @Router /address/{id} [get].
|
||||||
func (h Handler) GetAddress(c echo.Context) error {
|
func (h Handler) GetAddress(c echo.Context) error {
|
||||||
var req param.GetAddressRequest
|
var req param.GetAddressRequest
|
||||||
if bErr := echo.PathParamsBinder(c).Uint("id", &req.AddressID).BindError(); bErr != nil {
|
if bErr := echo.PathParamsBinder(c).Uint("id", &req.AddressID).BindError(); bErr != nil {
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
// @Success 200 {object} param.GetAllAddressesResponse
|
// @Success 200 {object} param.GetAllAddressesResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerBenefactor
|
// @Security AuthBearerBenefactor
|
||||||
// @Router /address/ [get]
|
// @Router /address/ [get].
|
||||||
func (h Handler) GetAddresses(c echo.Context) error {
|
func (h Handler) GetAddresses(c echo.Context) error {
|
||||||
var req param.GetAllAddressesRequest
|
var req param.GetAllAddressesRequest
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} addressparam.GetAllCitiesResponse
|
// @Success 200 {object} addressparam.GetAllCitiesResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Router /address/cities [get]
|
// @Router /address/cities [get].
|
||||||
func (h Handler) GetAllCities(c echo.Context) error {
|
func (h Handler) GetAllCities(c echo.Context) error {
|
||||||
var req addressparam.GetAllCitiesRequest
|
var req addressparam.GetAllCitiesRequest
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} addressparam.GetAllProvincesResponse
|
// @Success 200 {object} addressparam.GetAllProvincesResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Router /address/provinces [get]
|
// @Router /address/provinces [get].
|
||||||
func (h Handler) GetAllProvinces(c echo.Context) error {
|
func (h Handler) GetAllProvinces(c echo.Context) error {
|
||||||
var req addressparam.GetAllProvincesRequest
|
var req addressparam.GetAllProvincesRequest
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
// @Param Request body benefactoreparam.LoginOrRegisterRequest true "Login or register request details"
|
// @Param Request body benefactoreparam.LoginOrRegisterRequest true "Login or register request details"
|
||||||
// @Success 200 {object} benefactoreparam.LoginOrRegisterResponse
|
// @Success 200 {object} benefactoreparam.LoginOrRegisterResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Router /benefactor/login-register [post]
|
// @Router /benefactor/login-register [post].
|
||||||
func (h Handler) loginOrRegister(c echo.Context) error {
|
func (h Handler) loginOrRegister(c echo.Context) error {
|
||||||
var req benefactoreparam.LoginOrRegisterRequest
|
var req benefactoreparam.LoginOrRegisterRequest
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
// @Param Request body benefactoreparam.SendOtpRequest true "Send OTP request details"
|
// @Param Request body benefactoreparam.SendOtpRequest true "Send OTP request details"
|
||||||
// @Success 200 {object} benefactoreparam.SendOtpResponse
|
// @Success 200 {object} benefactoreparam.SendOtpResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Router /benefactor/send-otp [post]
|
// @Router /benefactor/send-otp [post].
|
||||||
func (h Handler) SendOtp(c echo.Context) error {
|
func (h Handler) SendOtp(c echo.Context) error {
|
||||||
var req benefactoreparam.SendOtpRequest
|
var req benefactoreparam.SendOtpRequest
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
// @Success 200 {object} param.KindBoxGetResponse
|
// @Success 200 {object} param.KindBoxGetResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerBenefactor
|
// @Security AuthBearerBenefactor
|
||||||
// @Router /benefactor/kindboxes/{id} [get]
|
// @Router /benefactor/kindboxes/{id} [get].
|
||||||
func (h Handler) Get(c echo.Context) error {
|
func (h Handler) Get(c echo.Context) error {
|
||||||
var req param.KindBoxGetRequest
|
var req param.KindBoxGetRequest
|
||||||
if bErr := c.Bind(&req); bErr != nil {
|
if bErr := c.Bind(&req); bErr != nil {
|
||||||
|
|
|
@ -18,11 +18,10 @@ import (
|
||||||
// @Success 200 {object} param.KindBoxReqAddResponse
|
// @Success 200 {object} param.KindBoxReqAddResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerBenefactor
|
// @Security AuthBearerBenefactor
|
||||||
// @Router /benefactor/kindboxreqs/ [post]
|
// @Router /benefactor/kindboxreqs/ [post].
|
||||||
func (h Handler) Add(c echo.Context) error {
|
func (h Handler) Add(c echo.Context) error {
|
||||||
req := param.KindBoxReqAddRequest{}
|
req := param.KindBoxReqAddRequest{}
|
||||||
if err := c.Bind(&req); err != nil {
|
if err := c.Bind(&req); err != nil {
|
||||||
|
|
||||||
return c.JSON(http.StatusBadRequest, echo.Map{
|
return c.JSON(http.StatusBadRequest, echo.Map{
|
||||||
"message": errmsg.ErrBadRequest,
|
"message": errmsg.ErrBadRequest,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
package benefactorkindboxreqhandler
|
package benefactorkindboxreqhandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
||||||
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
|
"git.gocasts.ir/ebhomengo/niki/pkg/claim"
|
||||||
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
httpmsg "git.gocasts.ir/ebhomengo/niki/pkg/http_msg"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// delete godoc
|
// delete godoc
|
||||||
|
@ -18,11 +19,10 @@ import (
|
||||||
// @Success 200 {object} param.KindBoxReqDeleteResponse
|
// @Success 200 {object} param.KindBoxReqDeleteResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerBenefactor
|
// @Security AuthBearerBenefactor
|
||||||
// @Router /benefactor/kindboxreqs/{id} [delete]
|
// @Router /benefactor/kindboxreqs/{id} [delete].
|
||||||
func (h Handler) Delete(c echo.Context) error {
|
func (h Handler) Delete(c echo.Context) error {
|
||||||
req := param.KindBoxReqDeleteRequest{}
|
req := param.KindBoxReqDeleteRequest{}
|
||||||
if bErr := echo.PathParamsBinder(c).Uint("id", &req.KindBoxReqID).BindError(); bErr != nil {
|
if bErr := echo.PathParamsBinder(c).Uint("id", &req.KindBoxReqID).BindError(); bErr != nil {
|
||||||
|
|
||||||
return echo.NewHTTPError(http.StatusBadRequest)
|
return echo.NewHTTPError(http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
claims := claim.GetClaimsFromEchoContext(c)
|
claims := claim.GetClaimsFromEchoContext(c)
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
// @Success 200 {object} param.KindBoxReqGetResponse
|
// @Success 200 {object} param.KindBoxReqGetResponse
|
||||||
// @Failure 400 {string} "Bad request"
|
// @Failure 400 {string} "Bad request"
|
||||||
// @Security AuthBearerBenefactor
|
// @Security AuthBearerBenefactor
|
||||||
// @Router /benefactor/kindboxreqs/{id} [get]
|
// @Router /benefactor/kindboxreqs/{id} [get].
|
||||||
func (h Handler) Get(c echo.Context) error {
|
func (h Handler) Get(c echo.Context) error {
|
||||||
var req param.KindBoxReqGetRequest
|
var req param.KindBoxReqGetRequest
|
||||||
if bErr := echo.PathParamsBinder(c).Uint("id", &req.KindBoxReqID).BindError(); bErr != nil {
|
if bErr := echo.PathParamsBinder(c).Uint("id", &req.KindBoxReqID).BindError(); bErr != nil {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package httpserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
config "git.gocasts.ir/ebhomengo/niki/config"
|
config "git.gocasts.ir/ebhomengo/niki/config"
|
||||||
adminhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/admin"
|
adminhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/admin"
|
||||||
adminkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box_req"
|
adminkindboxreqhandler "git.gocasts.ir/ebhomengo/niki/delivery/http_server/admin/kind_box_req"
|
||||||
|
@ -92,11 +93,11 @@ func (s Server) Serve() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterSwagger(s *echo.Echo, config config.Config) {
|
func RegisterSwagger(s *echo.Echo, config config.Config) {
|
||||||
//TODO: move this to a better place and make it more dynamic and configurable
|
// TODO: move this to a better place and make it more dynamic and configurable
|
||||||
docs.SwaggerInfo.Title = "NIKI API"
|
docs.SwaggerInfo.Title = "NIKI API"
|
||||||
docs.SwaggerInfo.Description = "This is the API documentation for the NIKI project"
|
docs.SwaggerInfo.Description = "This is the API documentation for the NIKI project"
|
||||||
docs.SwaggerInfo.Version = "1.0.0"
|
docs.SwaggerInfo.Version = "1.0.0"
|
||||||
//docs.SwaggerInfo.BasePath = "/api/v1"
|
// docs.SwaggerInfo.BasePath = "/api/v1"
|
||||||
docs.SwaggerInfo.Host = fmt.Sprintf("localhost:%d", config.HTTPServer.Port)
|
docs.SwaggerInfo.Host = fmt.Sprintf("localhost:%d", config.HTTPServer.Port)
|
||||||
|
|
||||||
s.GET("/swagger/*any", echoSwagger.WrapHandler)
|
s.GET("/swagger/*any", echoSwagger.WrapHandler)
|
||||||
|
|
|
@ -5,6 +5,7 @@ type AdminPermission string
|
||||||
const (
|
const (
|
||||||
AdminAdminRegisterPermission = AdminPermission("admin-register")
|
AdminAdminRegisterPermission = AdminPermission("admin-register")
|
||||||
AdminKindBoxReqAcceptPermission = AdminPermission("kindboxreq-accept")
|
AdminKindBoxReqAcceptPermission = AdminPermission("kindboxreq-accept")
|
||||||
|
AdminKindBoxReqAddPermission = AdminPermission("kindboxreq-add")
|
||||||
AdminKindBoxReqRejectPermission = AdminPermission("kindboxreq-reject")
|
AdminKindBoxReqRejectPermission = AdminPermission("kindboxreq-reject")
|
||||||
AdminKindBoxReqGetAllPermission = AdminPermission("kindboxreq-getall")
|
AdminKindBoxReqGetAllPermission = AdminPermission("kindboxreq-getall")
|
||||||
AdminKindBoxReqDeliverPermission = AdminPermission("kindboxreq-deliver")
|
AdminKindBoxReqDeliverPermission = AdminPermission("kindboxreq-deliver")
|
||||||
|
|
2
go.mod
2
go.mod
|
@ -16,6 +16,7 @@ require (
|
||||||
github.com/rubenv/sql-migrate v1.6.0
|
github.com/rubenv/sql-migrate v1.6.0
|
||||||
github.com/stretchr/testify v1.9.0
|
github.com/stretchr/testify v1.9.0
|
||||||
github.com/swaggo/echo-swagger v1.4.1
|
github.com/swaggo/echo-swagger v1.4.1
|
||||||
|
github.com/swaggo/swag v1.16.3
|
||||||
golang.org/x/crypto v0.23.0
|
golang.org/x/crypto v0.23.0
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1
|
||||||
)
|
)
|
||||||
|
@ -46,7 +47,6 @@ require (
|
||||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/swaggo/files/v2 v2.0.0 // indirect
|
github.com/swaggo/files/v2 v2.0.0 // indirect
|
||||||
github.com/swaggo/swag v1.16.3 // indirect
|
|
||||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||||
github.com/valyala/fasttemplate v1.2.2 // indirect
|
github.com/valyala/fasttemplate v1.2.2 // indirect
|
||||||
golang.org/x/net v0.25.0 // indirect
|
golang.org/x/net v0.25.0 // indirect
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package adminkindboxparam
|
package adminkindboxparam
|
||||||
|
|
||||||
import (
|
import (
|
||||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AddKindBoxRequest struct {
|
type AddKindBoxRequest struct {
|
||||||
|
|
|
@ -3,9 +3,11 @@ package adminkindboxreqparam
|
||||||
import entity "git.gocasts.ir/ebhomengo/niki/entity"
|
import entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
|
|
||||||
type KindBoxReqAddRequest struct {
|
type KindBoxReqAddRequest struct {
|
||||||
BenefactorID uint
|
BenefactorID uint `json:"benefactor_id" example:"1"`
|
||||||
TypeID uint
|
TypeID entity.KindBoxType `json:"type_id" example:"1"`
|
||||||
CountRequested uint
|
DeliverAddressID uint `json:"deliver_address_id" example:"1"`
|
||||||
|
DeliverReferDate string `json:"deliver_refer_date" example:"2025-01-02 15:04:05"`
|
||||||
|
CountRequested uint `json:"count_requested" example:"2"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KindBoxReqAddResponse struct {
|
type KindBoxReqAddResponse struct {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package mysqladmin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
@ -4,11 +4,12 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d DB) IsExistBenefactorByPhoneNumber(ctx context.Context, phoneNumber string) (bool, entity.Benefactor, error) {
|
func (d DB) IsExistBenefactorByPhoneNumber(ctx context.Context, phoneNumber string) (bool, entity.Benefactor, error) {
|
||||||
|
@ -56,7 +57,6 @@ func (d *DB) IsExistBenefactorByID(ctx context.Context, id uint) (bool, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func scanBenefactor(scanner mysql.Scanner) (entity.Benefactor, error) {
|
func scanBenefactor(scanner mysql.Scanner) (entity.Benefactor, error) {
|
||||||
|
|
||||||
var createdAt, updatedAt time.Time
|
var createdAt, updatedAt time.Time
|
||||||
var benefactor entity.Benefactor
|
var benefactor entity.Benefactor
|
||||||
// TODO - use db model and mapper between entity and db model OR use this approach
|
// TODO - use db model and mapper between entity and db model OR use this approach
|
||||||
|
|
|
@ -2,6 +2,7 @@ package mysqlkindboxreq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
@ -2,6 +2,7 @@ package mysqlkindboxreq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
@ -2,6 +2,7 @@ package mysqlkindboxreq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
entity "git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
@ -2,9 +2,10 @@ package mysqlkindboxreq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d DB) DeleteKindBoxReqByID(ctx context.Context, kindBoxReqID uint) error {
|
func (d DB) DeleteKindBoxReqByID(ctx context.Context, kindBoxReqID uint) error {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package mysqlkindboxreq
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
@ -2,6 +2,7 @@ package mysqlkindboxreq
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
@ -19,6 +19,8 @@ type Repository interface {
|
||||||
GetAdminByPhoneNumber(ctx context.Context, phoneNumber string) (entity.Admin, error)
|
GetAdminByPhoneNumber(ctx context.Context, phoneNumber string) (entity.Admin, error)
|
||||||
GetAdminByID(ctx context.Context, adminID uint) (entity.Admin, error)
|
GetAdminByID(ctx context.Context, adminID uint) (entity.Admin, error)
|
||||||
GetAllAgent(ctx context.Context) ([]entity.Admin, error)
|
GetAllAgent(ctx context.Context) ([]entity.Admin, error)
|
||||||
|
IsExistBenefactorByID(ctx context.Context, id uint) (bool, error)
|
||||||
|
GetAddressByID(ctx context.Context, id uint) (*entity.Address, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
|
|
|
@ -17,6 +17,7 @@ type Repository interface {
|
||||||
DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error
|
DeliverKindBoxReq(ctx context.Context, kindBoxReqID uint) error
|
||||||
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBoxReq, uint, error)
|
GetAllKindBoxReq(ctx context.Context, filter params.FilterRequest, pagination params.PaginationRequest, sort params.SortRequest) ([]entity.KindBoxReq, uint, error)
|
||||||
GetAwaitingDeliveryByAgent(ctx context.Context, kindBoxReqID uint, agentID uint) (entity.KindBoxReq, error)
|
GetAwaitingDeliveryByAgent(ctx context.Context, kindBoxReqID uint, agentID uint) (entity.KindBoxReq, error)
|
||||||
|
AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type KindBoxSvc interface {
|
type KindBoxSvc interface {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package benefactoraddressservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/address"
|
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/address"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package benefactorkindboxreqservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/repository/migrator"
|
"git.gocasts.ir/ebhomengo/niki/repository/migrator"
|
||||||
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
"git.gocasts.ir/ebhomengo/niki/repository/mysql"
|
||||||
|
|
||||||
//nolint
|
//nolint
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
)
|
)
|
||||||
|
|
|
@ -72,7 +72,7 @@ func SendOTP(t *testing.T) benefactoreparam.SendOtpResponse {
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint
|
// nolint
|
||||||
func CreateBenefactorWithSvc(t *testing.T, req benefactoreparam.LoginOrRegisterRequest) (benefactoreparam.LoginOrRegisterResponse, func()) {
|
func CreateBenefactorWithSvc(t *testing.T, req benefactoreparam.LoginOrRegisterRequest) (benefactoreparam.LoginOrRegisterResponse, func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
@ -88,7 +88,7 @@ func CreateBenefactorWithSvc(t *testing.T, req benefactoreparam.LoginOrRegisterR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint
|
// nolint
|
||||||
func CreateAddressWithSvc(t *testing.T, req addressparam.BenefactorAddAddressRequest) (addressparam.BenefactorAddAddressResponse, func()) {
|
func CreateAddressWithSvc(t *testing.T, req addressparam.BenefactorAddAddressRequest) (addressparam.BenefactorAddAddressResponse, func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
@ -52,7 +52,7 @@ func NewMockRepository(hasErr bool) *MockRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint
|
// nolint
|
||||||
func (m *MockRepository) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error) {
|
func (m *MockRepository) AddKindBoxReq(ctx context.Context, kindBoxReq entity.KindBoxReq) (entity.KindBoxReq, error) {
|
||||||
if m.hasErr {
|
if m.hasErr {
|
||||||
return entity.KindBoxReq{}, fmt.Errorf(RepoErr)
|
return entity.KindBoxReq{}, fmt.Errorf(RepoErr)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint
|
// nolint
|
||||||
func CreateBenefactor(t *testing.T, db *mysql.DB) (*entity.Benefactor, func()) {
|
func CreateBenefactor(t *testing.T, db *mysql.DB) (*entity.Benefactor, func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
benefactor := &entity.Benefactor{
|
benefactor := &entity.Benefactor{
|
||||||
|
@ -42,7 +42,7 @@ func CreateBenefactor(t *testing.T, db *mysql.DB) (*entity.Benefactor, func()) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint
|
// nolint
|
||||||
func CreateAddress(t *testing.T, db *mysql.DB, benfactorID uint) (*entity.Address, func()) {
|
func CreateAddress(t *testing.T, db *mysql.DB, benfactorID uint) (*entity.Address, func()) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
address := &entity.Address{
|
address := &entity.Address{
|
||||||
|
|
|
@ -25,11 +25,17 @@ type Repository interface {
|
||||||
|
|
||||||
type AdminSvc interface {
|
type AdminSvc interface {
|
||||||
AdminExistByID(ctx context.Context, req param.AdminExistByIDRequest) (param.AdminExistByIDResponse, error)
|
AdminExistByID(ctx context.Context, req param.AdminExistByIDRequest) (param.AdminExistByIDResponse, error)
|
||||||
|
BenefactorExistByID(ctx context.Context, request param.BenefactorExistByIDRequest) (param.BenefactorExistByIDResponse, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
type AddressSvc interface {
|
||||||
|
AddressExistByID(ctx context.Context, request param.GetAddressByIDRequest) (param.GetAddressByIDResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Validator struct {
|
type Validator struct {
|
||||||
repo Repository
|
repo Repository
|
||||||
adminSvc AdminSvc
|
adminSvc AdminSvc
|
||||||
|
addressSvc AddressSvc
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(repo Repository, adminSvc AdminSvc) Validator {
|
func New(repo Repository, adminSvc AdminSvc) Validator {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package benefactorkindboxreqvalidator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/kind_box_req"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
richerror "git.gocasts.ir/ebhomengo/niki/pkg/rich_error"
|
||||||
|
|
|
@ -3,13 +3,14 @@ package benefactorkindboxreqvalidator
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.gocasts.ir/ebhomengo/niki/entity"
|
"git.gocasts.ir/ebhomengo/niki/entity"
|
||||||
refertimeparam "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
|
refertimeparam "git.gocasts.ir/ebhomengo/niki/param/admin/refer_time"
|
||||||
addressparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/address"
|
addressparam "git.gocasts.ir/ebhomengo/niki/param/benefactor/address"
|
||||||
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactore"
|
param "git.gocasts.ir/ebhomengo/niki/param/benefactor/benefactore"
|
||||||
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
errmsg "git.gocasts.ir/ebhomengo/niki/pkg/err_msg"
|
||||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -3,27 +3,27 @@
|
||||||
//
|
//
|
||||||
// For example, the dependencies of the stdlib `strings` package can be resolved like so:
|
// For example, the dependencies of the stdlib `strings` package can be resolved like so:
|
||||||
//
|
//
|
||||||
// import "github.com/KyleBanks/depth"
|
// import "github.com/KyleBanks/depth"
|
||||||
//
|
//
|
||||||
// var t depth.Tree
|
// var t depth.Tree
|
||||||
// err := t.Resolve("strings")
|
// err := t.Resolve("strings")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// // Output: "strings has 4 dependencies."
|
// // Output: "strings has 4 dependencies."
|
||||||
// log.Printf("%v has %v dependencies.", t.Root.Name, len(t.Root.Deps))
|
// log.Printf("%v has %v dependencies.", t.Root.Name, len(t.Root.Deps))
|
||||||
//
|
//
|
||||||
// For additional customization, simply set the appropriate flags on the `Tree` before resolving:
|
// For additional customization, simply set the appropriate flags on the `Tree` before resolving:
|
||||||
//
|
//
|
||||||
// import "github.com/KyleBanks/depth"
|
// import "github.com/KyleBanks/depth"
|
||||||
//
|
//
|
||||||
// t := depth.Tree {
|
// t := depth.Tree {
|
||||||
// ResolveInternal: true,
|
// ResolveInternal: true,
|
||||||
// ResolveTest: true,
|
// ResolveTest: true,
|
||||||
// MaxDepth: 10,
|
// MaxDepth: 10,
|
||||||
// }
|
// }
|
||||||
// err := t.Resolve("strings")
|
// err := t.Resolve("strings")
|
||||||
package depth
|
package depth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -72,13 +72,13 @@ var ParamTagMap = map[string]ParamValidator{
|
||||||
|
|
||||||
// ParamTagRegexMap maps param tags to their respective regexes.
|
// ParamTagRegexMap maps param tags to their respective regexes.
|
||||||
var ParamTagRegexMap = map[string]*regexp.Regexp{
|
var ParamTagRegexMap = map[string]*regexp.Regexp{
|
||||||
"range": regexp.MustCompile("^range\\((\\d+)\\|(\\d+)\\)$"),
|
"range": regexp.MustCompile("^range\\((\\d+)\\|(\\d+)\\)$"),
|
||||||
"length": regexp.MustCompile("^length\\((\\d+)\\|(\\d+)\\)$"),
|
"length": regexp.MustCompile("^length\\((\\d+)\\|(\\d+)\\)$"),
|
||||||
"runelength": regexp.MustCompile("^runelength\\((\\d+)\\|(\\d+)\\)$"),
|
"runelength": regexp.MustCompile("^runelength\\((\\d+)\\|(\\d+)\\)$"),
|
||||||
"stringlength": regexp.MustCompile("^stringlength\\((\\d+)\\|(\\d+)\\)$"),
|
"stringlength": regexp.MustCompile("^stringlength\\((\\d+)\\|(\\d+)\\)$"),
|
||||||
"in": regexp.MustCompile(`^in\((.*)\)`),
|
"in": regexp.MustCompile(`^in\((.*)\)`),
|
||||||
"matches": regexp.MustCompile(`^matches\((.+)\)$`),
|
"matches": regexp.MustCompile(`^matches\((.+)\)$`),
|
||||||
"rsapub": regexp.MustCompile("^rsapub\\((\\d+)\\)$"),
|
"rsapub": regexp.MustCompile("^rsapub\\((\\d+)\\)$"),
|
||||||
"minstringlength": regexp.MustCompile("^minstringlength\\((\\d+)\\)$"),
|
"minstringlength": regexp.MustCompile("^minstringlength\\((\\d+)\\)$"),
|
||||||
"maxstringlength": regexp.MustCompile("^maxstringlength\\((\\d+)\\)$"),
|
"maxstringlength": regexp.MustCompile("^maxstringlength\\((\\d+)\\)$"),
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ type ISO3166Entry struct {
|
||||||
Numeric string
|
Numeric string
|
||||||
}
|
}
|
||||||
|
|
||||||
//ISO3166List based on https://www.iso.org/obp/ui/#search/code/ Code Type "Officially Assigned Codes"
|
// ISO3166List based on https://www.iso.org/obp/ui/#search/code/ Code Type "Officially Assigned Codes"
|
||||||
var ISO3166List = []ISO3166Entry{
|
var ISO3166List = []ISO3166Entry{
|
||||||
{"Afghanistan", "Afghanistan (l')", "AF", "AFG", "004"},
|
{"Afghanistan", "Afghanistan (l')", "AF", "AFG", "004"},
|
||||||
{"Albania", "Albanie (l')", "AL", "ALB", "008"},
|
{"Albania", "Albanie (l')", "AL", "ALB", "008"},
|
||||||
|
@ -463,7 +463,7 @@ type ISO693Entry struct {
|
||||||
English string
|
English string
|
||||||
}
|
}
|
||||||
|
|
||||||
//ISO693List based on http://data.okfn.org/data/core/language-codes/r/language-codes-3b2.json
|
// ISO693List based on http://data.okfn.org/data/core/language-codes/r/language-codes-3b2.json
|
||||||
var ISO693List = []ISO693Entry{
|
var ISO693List = []ISO693Entry{
|
||||||
{Alpha3bCode: "aar", Alpha2Code: "aa", English: "Afar"},
|
{Alpha3bCode: "aar", Alpha2Code: "aa", English: "Afar"},
|
||||||
{Alpha3bCode: "abk", Alpha2Code: "ab", English: "Abkhazian"},
|
{Alpha3bCode: "abk", Alpha2Code: "ab", English: "Abkhazian"},
|
||||||
|
|
|
@ -37,25 +37,32 @@ const RF3339WithoutZone = "2006-01-02T15:04:05"
|
||||||
// SetFieldsRequiredByDefault causes validation to fail when struct fields
|
// SetFieldsRequiredByDefault causes validation to fail when struct fields
|
||||||
// do not include validations or are not explicitly marked as exempt (using `valid:"-"` or `valid:"email,optional"`).
|
// do not include validations or are not explicitly marked as exempt (using `valid:"-"` or `valid:"email,optional"`).
|
||||||
// This struct definition will fail govalidator.ValidateStruct() (and the field values do not matter):
|
// This struct definition will fail govalidator.ValidateStruct() (and the field values do not matter):
|
||||||
// type exampleStruct struct {
|
//
|
||||||
// Name string ``
|
// type exampleStruct struct {
|
||||||
// Email string `valid:"email"`
|
// Name string ``
|
||||||
|
// Email string `valid:"email"`
|
||||||
|
//
|
||||||
// This, however, will only fail when Email is empty or an invalid email address:
|
// This, however, will only fail when Email is empty or an invalid email address:
|
||||||
// type exampleStruct2 struct {
|
//
|
||||||
// Name string `valid:"-"`
|
// type exampleStruct2 struct {
|
||||||
// Email string `valid:"email"`
|
// Name string `valid:"-"`
|
||||||
|
// Email string `valid:"email"`
|
||||||
|
//
|
||||||
// Lastly, this will only fail when Email is an invalid email address but not when it's empty:
|
// Lastly, this will only fail when Email is an invalid email address but not when it's empty:
|
||||||
// type exampleStruct2 struct {
|
//
|
||||||
// Name string `valid:"-"`
|
// type exampleStruct2 struct {
|
||||||
// Email string `valid:"email,optional"`
|
// Name string `valid:"-"`
|
||||||
|
// Email string `valid:"email,optional"`
|
||||||
func SetFieldsRequiredByDefault(value bool) {
|
func SetFieldsRequiredByDefault(value bool) {
|
||||||
fieldsRequiredByDefault = value
|
fieldsRequiredByDefault = value
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNilPtrAllowedByRequired causes validation to pass for nil ptrs when a field is set to required.
|
// SetNilPtrAllowedByRequired causes validation to pass for nil ptrs when a field is set to required.
|
||||||
// The validation will still reject ptr fields in their zero value state. Example with this enabled:
|
// The validation will still reject ptr fields in their zero value state. Example with this enabled:
|
||||||
// type exampleStruct struct {
|
//
|
||||||
// Name *string `valid:"required"`
|
// type exampleStruct struct {
|
||||||
|
// Name *string `valid:"required"`
|
||||||
|
//
|
||||||
// With `Name` set to "", this will be considered invalid input and will cause a validation error.
|
// With `Name` set to "", this will be considered invalid input and will cause a validation error.
|
||||||
// With `Name` set to nil, this will be considered valid by validation.
|
// With `Name` set to nil, this will be considered valid by validation.
|
||||||
// By default this is disabled.
|
// By default this is disabled.
|
||||||
|
@ -154,8 +161,8 @@ func IsAlpha(str string) bool {
|
||||||
return rxAlpha.MatchString(str)
|
return rxAlpha.MatchString(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
//IsUTFLetter check if the string contains only unicode letter characters.
|
// IsUTFLetter check if the string contains only unicode letter characters.
|
||||||
//Similar to IsAlpha but for all languages. Empty string is valid.
|
// Similar to IsAlpha but for all languages. Empty string is valid.
|
||||||
func IsUTFLetter(str string) bool {
|
func IsUTFLetter(str string) bool {
|
||||||
if IsNull(str) {
|
if IsNull(str) {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -3,13 +3,12 @@ package gofakeit
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TemplateOptions defines values needed for template document generation
|
// TemplateOptions defines values needed for template document generation
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
// tag is deprecated and thus should not be used.
|
// tag is deprecated and thus should not be used.
|
||||||
// Go versions prior to 1.4 are disabled because they use a different layout
|
// Go versions prior to 1.4 are disabled because they use a different layout
|
||||||
// for interfaces which make the implementation of unsafeReflectValue more complex.
|
// for interfaces which make the implementation of unsafeReflectValue more complex.
|
||||||
|
//go:build !js && !appengine && !safe && !disableunsafe && go1.4
|
||||||
// +build !js,!appengine,!safe,!disableunsafe,go1.4
|
// +build !js,!appengine,!safe,!disableunsafe,go1.4
|
||||||
|
|
||||||
package spew
|
package spew
|
||||||
|
|
|
@ -254,15 +254,15 @@ pointer addresses used to indirect to the final value. It provides the
|
||||||
following features over the built-in printing facilities provided by the fmt
|
following features over the built-in printing facilities provided by the fmt
|
||||||
package:
|
package:
|
||||||
|
|
||||||
* Pointers are dereferenced and followed
|
- Pointers are dereferenced and followed
|
||||||
* Circular data structures are detected and handled properly
|
- Circular data structures are detected and handled properly
|
||||||
* Custom Stringer/error interfaces are optionally invoked, including
|
- Custom Stringer/error interfaces are optionally invoked, including
|
||||||
on unexported types
|
on unexported types
|
||||||
* Custom types which only implement the Stringer/error interfaces via
|
- Custom types which only implement the Stringer/error interfaces via
|
||||||
a pointer receiver are optionally invoked when passing non-pointer
|
a pointer receiver are optionally invoked when passing non-pointer
|
||||||
variables
|
variables
|
||||||
* Byte arrays and slices are dumped like the hexdump -C command which
|
- Byte arrays and slices are dumped like the hexdump -C command which
|
||||||
includes offsets, byte values in hex, and ASCII output
|
includes offsets, byte values in hex, and ASCII output
|
||||||
|
|
||||||
The configuration options are controlled by modifying the public members
|
The configuration options are controlled by modifying the public members
|
||||||
of c. See ConfigState for options documentation.
|
of c. See ConfigState for options documentation.
|
||||||
|
@ -295,12 +295,12 @@ func (c *ConfigState) convertArgs(args []interface{}) (formatters []interface{})
|
||||||
|
|
||||||
// NewDefaultConfig returns a ConfigState with the following default settings.
|
// NewDefaultConfig returns a ConfigState with the following default settings.
|
||||||
//
|
//
|
||||||
// Indent: " "
|
// Indent: " "
|
||||||
// MaxDepth: 0
|
// MaxDepth: 0
|
||||||
// DisableMethods: false
|
// DisableMethods: false
|
||||||
// DisablePointerMethods: false
|
// DisablePointerMethods: false
|
||||||
// ContinueOnMethod: false
|
// ContinueOnMethod: false
|
||||||
// SortKeys: false
|
// SortKeys: false
|
||||||
func NewDefaultConfig() *ConfigState {
|
func NewDefaultConfig() *ConfigState {
|
||||||
return &ConfigState{Indent: " "}
|
return &ConfigState{Indent: " "}
|
||||||
}
|
}
|
||||||
|
|
|
@ -488,15 +488,15 @@ pointer addresses used to indirect to the final value. It provides the
|
||||||
following features over the built-in printing facilities provided by the fmt
|
following features over the built-in printing facilities provided by the fmt
|
||||||
package:
|
package:
|
||||||
|
|
||||||
* Pointers are dereferenced and followed
|
- Pointers are dereferenced and followed
|
||||||
* Circular data structures are detected and handled properly
|
- Circular data structures are detected and handled properly
|
||||||
* Custom Stringer/error interfaces are optionally invoked, including
|
- Custom Stringer/error interfaces are optionally invoked, including
|
||||||
on unexported types
|
on unexported types
|
||||||
* Custom types which only implement the Stringer/error interfaces via
|
- Custom types which only implement the Stringer/error interfaces via
|
||||||
a pointer receiver are optionally invoked when passing non-pointer
|
a pointer receiver are optionally invoked when passing non-pointer
|
||||||
variables
|
variables
|
||||||
* Byte arrays and slices are dumped like the hexdump -C command which
|
- Byte arrays and slices are dumped like the hexdump -C command which
|
||||||
includes offsets, byte values in hex, and ASCII output
|
includes offsets, byte values in hex, and ASCII output
|
||||||
|
|
||||||
The configuration options are controlled by an exported package global,
|
The configuration options are controlled by an exported package global,
|
||||||
spew.Config. See ConfigState for options documentation.
|
spew.Config. See ConfigState for options documentation.
|
||||||
|
|
|
@ -95,8 +95,8 @@ func (f *Field) Zero() error {
|
||||||
// of a nested struct . A struct tag with the content of "-" ignores the
|
// of a nested struct . A struct tag with the content of "-" ignores the
|
||||||
// checking of that particular field. Example:
|
// checking of that particular field. Example:
|
||||||
//
|
//
|
||||||
// // Field is ignored by this package.
|
// // Field is ignored by this package.
|
||||||
// Field *http.Request `structs:"-"`
|
// Field *http.Request `structs:"-"`
|
||||||
//
|
//
|
||||||
// It panics if field is not exported or if field's kind is not struct
|
// It panics if field is not exported or if field's kind is not struct
|
||||||
func (f *Field) Fields() []*Field {
|
func (f *Field) Fields() []*Field {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package structs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,43 +37,43 @@ func New(s interface{}) *Struct {
|
||||||
// can be changed in the struct field's tag value. The "structs" key in the
|
// can be changed in the struct field's tag value. The "structs" key in the
|
||||||
// struct's field tag value is the key name. Example:
|
// struct's field tag value is the key name. Example:
|
||||||
//
|
//
|
||||||
// // Field appears in map as key "myName".
|
// // Field appears in map as key "myName".
|
||||||
// Name string `structs:"myName"`
|
// Name string `structs:"myName"`
|
||||||
//
|
//
|
||||||
// A tag value with the content of "-" ignores that particular field. Example:
|
// A tag value with the content of "-" ignores that particular field. Example:
|
||||||
//
|
//
|
||||||
// // Field is ignored by this package.
|
// // Field is ignored by this package.
|
||||||
// Field bool `structs:"-"`
|
// Field bool `structs:"-"`
|
||||||
//
|
//
|
||||||
// A tag value with the content of "string" uses the stringer to get the value. Example:
|
// A tag value with the content of "string" uses the stringer to get the value. Example:
|
||||||
//
|
//
|
||||||
// // The value will be output of Animal's String() func.
|
// // The value will be output of Animal's String() func.
|
||||||
// // Map will panic if Animal does not implement String().
|
// // Map will panic if Animal does not implement String().
|
||||||
// Field *Animal `structs:"field,string"`
|
// Field *Animal `structs:"field,string"`
|
||||||
//
|
//
|
||||||
// A tag value with the option of "flatten" used in a struct field is to flatten its fields
|
// A tag value with the option of "flatten" used in a struct field is to flatten its fields
|
||||||
// in the output map. Example:
|
// in the output map. Example:
|
||||||
//
|
//
|
||||||
// // The FieldStruct's fields will be flattened into the output map.
|
// // The FieldStruct's fields will be flattened into the output map.
|
||||||
// FieldStruct time.Time `structs:",flatten"`
|
// FieldStruct time.Time `structs:",flatten"`
|
||||||
//
|
//
|
||||||
// A tag value with the option of "omitnested" stops iterating further if the type
|
// A tag value with the option of "omitnested" stops iterating further if the type
|
||||||
// is a struct. Example:
|
// is a struct. Example:
|
||||||
//
|
//
|
||||||
// // Field is not processed further by this package.
|
// // Field is not processed further by this package.
|
||||||
// Field time.Time `structs:"myName,omitnested"`
|
// Field time.Time `structs:"myName,omitnested"`
|
||||||
// Field *http.Request `structs:",omitnested"`
|
// Field *http.Request `structs:",omitnested"`
|
||||||
//
|
//
|
||||||
// A tag value with the option of "omitempty" ignores that particular field if
|
// A tag value with the option of "omitempty" ignores that particular field if
|
||||||
// the field value is empty. Example:
|
// the field value is empty. Example:
|
||||||
//
|
//
|
||||||
// // Field appears in map as key "myName", but the field is
|
// // Field appears in map as key "myName", but the field is
|
||||||
// // skipped if empty.
|
// // skipped if empty.
|
||||||
// Field string `structs:"myName,omitempty"`
|
// Field string `structs:"myName,omitempty"`
|
||||||
//
|
//
|
||||||
// // Field appears in map as key "Field" (the default), but
|
// // Field appears in map as key "Field" (the default), but
|
||||||
// // the field is skipped if empty.
|
// // the field is skipped if empty.
|
||||||
// Field string `structs:",omitempty"`
|
// Field string `structs:",omitempty"`
|
||||||
//
|
//
|
||||||
// Note that only exported fields of a struct can be accessed, non exported
|
// Note that only exported fields of a struct can be accessed, non exported
|
||||||
// fields will be neglected.
|
// fields will be neglected.
|
||||||
|
@ -153,21 +152,21 @@ func (s *Struct) FillMap(out map[string]interface{}) {
|
||||||
// struct tag with the content of "-" ignores the that particular field.
|
// struct tag with the content of "-" ignores the that particular field.
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
// // Field is ignored by this package.
|
// // Field is ignored by this package.
|
||||||
// Field int `structs:"-"`
|
// Field int `structs:"-"`
|
||||||
//
|
//
|
||||||
// A value with the option of "omitnested" stops iterating further if the type
|
// A value with the option of "omitnested" stops iterating further if the type
|
||||||
// is a struct. Example:
|
// is a struct. Example:
|
||||||
//
|
//
|
||||||
// // Fields is not processed further by this package.
|
// // Fields is not processed further by this package.
|
||||||
// Field time.Time `structs:",omitnested"`
|
// Field time.Time `structs:",omitnested"`
|
||||||
// Field *http.Request `structs:",omitnested"`
|
// Field *http.Request `structs:",omitnested"`
|
||||||
//
|
//
|
||||||
// A tag value with the option of "omitempty" ignores that particular field and
|
// A tag value with the option of "omitempty" ignores that particular field and
|
||||||
// is not added to the values if the field value is empty. Example:
|
// is not added to the values if the field value is empty. Example:
|
||||||
//
|
//
|
||||||
// // Field is skipped if empty
|
// // Field is skipped if empty
|
||||||
// Field string `structs:",omitempty"`
|
// Field string `structs:",omitempty"`
|
||||||
//
|
//
|
||||||
// Note that only exported fields of a struct can be accessed, non exported
|
// Note that only exported fields of a struct can be accessed, non exported
|
||||||
// fields will be neglected.
|
// fields will be neglected.
|
||||||
|
@ -215,8 +214,8 @@ func (s *Struct) Values() []interface{} {
|
||||||
// Fields returns a slice of Fields. A struct tag with the content of "-"
|
// Fields returns a slice of Fields. A struct tag with the content of "-"
|
||||||
// ignores the checking of that particular field. Example:
|
// ignores the checking of that particular field. Example:
|
||||||
//
|
//
|
||||||
// // Field is ignored by this package.
|
// // Field is ignored by this package.
|
||||||
// Field bool `structs:"-"`
|
// Field bool `structs:"-"`
|
||||||
//
|
//
|
||||||
// It panics if s's kind is not struct.
|
// It panics if s's kind is not struct.
|
||||||
func (s *Struct) Fields() []*Field {
|
func (s *Struct) Fields() []*Field {
|
||||||
|
@ -226,8 +225,8 @@ func (s *Struct) Fields() []*Field {
|
||||||
// Names returns a slice of field names. A struct tag with the content of "-"
|
// Names returns a slice of field names. A struct tag with the content of "-"
|
||||||
// ignores the checking of that particular field. Example:
|
// ignores the checking of that particular field. Example:
|
||||||
//
|
//
|
||||||
// // Field is ignored by this package.
|
// // Field is ignored by this package.
|
||||||
// Field bool `structs:"-"`
|
// Field bool `structs:"-"`
|
||||||
//
|
//
|
||||||
// It panics if s's kind is not struct.
|
// It panics if s's kind is not struct.
|
||||||
func (s *Struct) Names() []string {
|
func (s *Struct) Names() []string {
|
||||||
|
@ -303,15 +302,15 @@ func (s *Struct) FieldOk(name string) (*Field, bool) {
|
||||||
// initialized) A struct tag with the content of "-" ignores the checking of
|
// initialized) A struct tag with the content of "-" ignores the checking of
|
||||||
// that particular field. Example:
|
// that particular field. Example:
|
||||||
//
|
//
|
||||||
// // Field is ignored by this package.
|
// // Field is ignored by this package.
|
||||||
// Field bool `structs:"-"`
|
// Field bool `structs:"-"`
|
||||||
//
|
//
|
||||||
// A value with the option of "omitnested" stops iterating further if the type
|
// A value with the option of "omitnested" stops iterating further if the type
|
||||||
// is a struct. Example:
|
// is a struct. Example:
|
||||||
//
|
//
|
||||||
// // Field is not processed further by this package.
|
// // Field is not processed further by this package.
|
||||||
// Field time.Time `structs:"myName,omitnested"`
|
// Field time.Time `structs:"myName,omitnested"`
|
||||||
// Field *http.Request `structs:",omitnested"`
|
// Field *http.Request `structs:",omitnested"`
|
||||||
//
|
//
|
||||||
// Note that only exported fields of a struct can be accessed, non exported
|
// Note that only exported fields of a struct can be accessed, non exported
|
||||||
// fields will be neglected. It panics if s's kind is not struct.
|
// fields will be neglected. It panics if s's kind is not struct.
|
||||||
|
@ -350,15 +349,15 @@ func (s *Struct) IsZero() bool {
|
||||||
// A struct tag with the content of "-" ignores the checking of that particular
|
// A struct tag with the content of "-" ignores the checking of that particular
|
||||||
// field. Example:
|
// field. Example:
|
||||||
//
|
//
|
||||||
// // Field is ignored by this package.
|
// // Field is ignored by this package.
|
||||||
// Field bool `structs:"-"`
|
// Field bool `structs:"-"`
|
||||||
//
|
//
|
||||||
// A value with the option of "omitnested" stops iterating further if the type
|
// A value with the option of "omitnested" stops iterating further if the type
|
||||||
// is a struct. Example:
|
// is a struct. Example:
|
||||||
//
|
//
|
||||||
// // Field is not processed further by this package.
|
// // Field is not processed further by this package.
|
||||||
// Field time.Time `structs:"myName,omitnested"`
|
// Field time.Time `structs:"myName,omitnested"`
|
||||||
// Field *http.Request `structs:",omitnested"`
|
// Field *http.Request `structs:",omitnested"`
|
||||||
//
|
//
|
||||||
// Note that only exported fields of a struct can be accessed, non exported
|
// Note that only exported fields of a struct can be accessed, non exported
|
||||||
// fields will be neglected. It panics if s's kind is not struct.
|
// fields will be neglected. It panics if s's kind is not struct.
|
||||||
|
|
|
@ -347,8 +347,9 @@ const (
|
||||||
// 4) simpleLetterEqualFold, no specials, no non-letters.
|
// 4) simpleLetterEqualFold, no specials, no non-letters.
|
||||||
//
|
//
|
||||||
// The letters S and K are special because they map to 3 runes, not just 2:
|
// The letters S and K are special because they map to 3 runes, not just 2:
|
||||||
// * S maps to s and to U+017F 'ſ' Latin small letter long s
|
// - S maps to s and to U+017F 'ſ' Latin small letter long s
|
||||||
// * k maps to K and to U+212A 'K' Kelvin sign
|
// - k maps to K and to U+212A 'K' Kelvin sign
|
||||||
|
//
|
||||||
// See http://play.golang.org/p/tTxjOc0OGo
|
// See http://play.golang.org/p/tTxjOc0OGo
|
||||||
//
|
//
|
||||||
// The returned function is specialized for matching against s and
|
// The returned function is specialized for matching against s and
|
||||||
|
|
|
@ -64,12 +64,12 @@ func JSONToYAML(j []byte) ([]byte, error) {
|
||||||
// this method should be a no-op.
|
// this method should be a no-op.
|
||||||
//
|
//
|
||||||
// Things YAML can do that are not supported by JSON:
|
// Things YAML can do that are not supported by JSON:
|
||||||
// * In YAML you can have binary and null keys in your maps. These are invalid
|
// - In YAML you can have binary and null keys in your maps. These are invalid
|
||||||
// in JSON. (int and float keys are converted to strings.)
|
// in JSON. (int and float keys are converted to strings.)
|
||||||
// * Binary data in YAML with the !!binary tag is not supported. If you want to
|
// - Binary data in YAML with the !!binary tag is not supported. If you want to
|
||||||
// use binary data with this library, encode the data as base64 as usual but do
|
// use binary data with this library, encode the data as base64 as usual but do
|
||||||
// not use the !!binary tag in your YAML. This will ensure the original base64
|
// not use the !!binary tag in your YAML. This will ensure the original base64
|
||||||
// encoded data makes it all the way through to the JSON.
|
// encoded data makes it all the way through to the JSON.
|
||||||
func YAMLToJSON(y []byte) ([]byte, error) {
|
func YAMLToJSON(y []byte) ([]byte, error) {
|
||||||
return yamlToJSON(y, nil)
|
return yamlToJSON(y, nil)
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,9 +24,8 @@ import (
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
//
|
//
|
||||||
// dialect := gorp.MySQLDialect{"InnoDB", "UTF8"}
|
// dialect := gorp.MySQLDialect{"InnoDB", "UTF8"}
|
||||||
// dbmap := &gorp.DbMap{Db: db, Dialect: dialect}
|
// dbmap := &gorp.DbMap{Db: db, Dialect: dialect}
|
||||||
//
|
|
||||||
type DbMap struct {
|
type DbMap struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
|
|
||||||
|
|
|
@ -5,148 +5,148 @@
|
||||||
package gorp
|
package gorp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SnowflakeDialect struct {
|
type SnowflakeDialect struct {
|
||||||
suffix string
|
suffix string
|
||||||
LowercaseFields bool
|
LowercaseFields bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) QuerySuffix() string { return ";" }
|
func (d SnowflakeDialect) QuerySuffix() string { return ";" }
|
||||||
|
|
||||||
func (d SnowflakeDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string {
|
func (d SnowflakeDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool) string {
|
||||||
switch val.Kind() {
|
switch val.Kind() {
|
||||||
case reflect.Ptr:
|
case reflect.Ptr:
|
||||||
return d.ToSqlType(val.Elem(), maxsize, isAutoIncr)
|
return d.ToSqlType(val.Elem(), maxsize, isAutoIncr)
|
||||||
case reflect.Bool:
|
case reflect.Bool:
|
||||||
return "boolean"
|
return "boolean"
|
||||||
case reflect.Int,
|
case reflect.Int,
|
||||||
reflect.Int8,
|
reflect.Int8,
|
||||||
reflect.Int16,
|
reflect.Int16,
|
||||||
reflect.Int32,
|
reflect.Int32,
|
||||||
reflect.Uint,
|
reflect.Uint,
|
||||||
reflect.Uint8,
|
reflect.Uint8,
|
||||||
reflect.Uint16,
|
reflect.Uint16,
|
||||||
reflect.Uint32:
|
reflect.Uint32:
|
||||||
|
|
||||||
if isAutoIncr {
|
if isAutoIncr {
|
||||||
return "serial"
|
return "serial"
|
||||||
}
|
}
|
||||||
return "integer"
|
return "integer"
|
||||||
case reflect.Int64, reflect.Uint64:
|
case reflect.Int64, reflect.Uint64:
|
||||||
if isAutoIncr {
|
if isAutoIncr {
|
||||||
return "bigserial"
|
return "bigserial"
|
||||||
}
|
}
|
||||||
return "bigint"
|
return "bigint"
|
||||||
case reflect.Float64:
|
case reflect.Float64:
|
||||||
return "double precision"
|
return "double precision"
|
||||||
case reflect.Float32:
|
case reflect.Float32:
|
||||||
return "real"
|
return "real"
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
if val.Elem().Kind() == reflect.Uint8 {
|
if val.Elem().Kind() == reflect.Uint8 {
|
||||||
return "binary"
|
return "binary"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch val.Name() {
|
switch val.Name() {
|
||||||
case "NullInt64":
|
case "NullInt64":
|
||||||
return "bigint"
|
return "bigint"
|
||||||
case "NullFloat64":
|
case "NullFloat64":
|
||||||
return "double precision"
|
return "double precision"
|
||||||
case "NullBool":
|
case "NullBool":
|
||||||
return "boolean"
|
return "boolean"
|
||||||
case "Time", "NullTime":
|
case "Time", "NullTime":
|
||||||
return "timestamp with time zone"
|
return "timestamp with time zone"
|
||||||
}
|
}
|
||||||
|
|
||||||
if maxsize > 0 {
|
if maxsize > 0 {
|
||||||
return fmt.Sprintf("varchar(%d)", maxsize)
|
return fmt.Sprintf("varchar(%d)", maxsize)
|
||||||
} else {
|
} else {
|
||||||
return "text"
|
return "text"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns empty string
|
// Returns empty string
|
||||||
func (d SnowflakeDialect) AutoIncrStr() string {
|
func (d SnowflakeDialect) AutoIncrStr() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) AutoIncrBindValue() string {
|
func (d SnowflakeDialect) AutoIncrBindValue() string {
|
||||||
return "default"
|
return "default"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) AutoIncrInsertSuffix(col *ColumnMap) string {
|
func (d SnowflakeDialect) AutoIncrInsertSuffix(col *ColumnMap) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns suffix
|
// Returns suffix
|
||||||
func (d SnowflakeDialect) CreateTableSuffix() string {
|
func (d SnowflakeDialect) CreateTableSuffix() string {
|
||||||
return d.suffix
|
return d.suffix
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) CreateIndexSuffix() string {
|
func (d SnowflakeDialect) CreateIndexSuffix() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) DropIndexSuffix() string {
|
func (d SnowflakeDialect) DropIndexSuffix() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) TruncateClause() string {
|
func (d SnowflakeDialect) TruncateClause() string {
|
||||||
return "truncate"
|
return "truncate"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns "$(i+1)"
|
// Returns "$(i+1)"
|
||||||
func (d SnowflakeDialect) BindVar(i int) string {
|
func (d SnowflakeDialect) BindVar(i int) string {
|
||||||
return "?"
|
return "?"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) InsertAutoIncrToTarget(exec SqlExecutor, insertSql string, target interface{}, params ...interface{}) error {
|
func (d SnowflakeDialect) InsertAutoIncrToTarget(exec SqlExecutor, insertSql string, target interface{}, params ...interface{}) error {
|
||||||
rows, err := exec.Query(insertSql, params...)
|
rows, err := exec.Query(insertSql, params...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
if !rows.Next() {
|
if !rows.Next() {
|
||||||
return fmt.Errorf("No serial value returned for insert: %s Encountered error: %s", insertSql, rows.Err())
|
return fmt.Errorf("No serial value returned for insert: %s Encountered error: %s", insertSql, rows.Err())
|
||||||
}
|
}
|
||||||
if err := rows.Scan(target); err != nil {
|
if err := rows.Scan(target); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if rows.Next() {
|
if rows.Next() {
|
||||||
return fmt.Errorf("more than two serial value returned for insert: %s", insertSql)
|
return fmt.Errorf("more than two serial value returned for insert: %s", insertSql)
|
||||||
}
|
}
|
||||||
return rows.Err()
|
return rows.Err()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) QuoteField(f string) string {
|
func (d SnowflakeDialect) QuoteField(f string) string {
|
||||||
if d.LowercaseFields {
|
if d.LowercaseFields {
|
||||||
return `"` + strings.ToLower(f) + `"`
|
return `"` + strings.ToLower(f) + `"`
|
||||||
}
|
}
|
||||||
return `"` + f + `"`
|
return `"` + f + `"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) QuotedTableForQuery(schema string, table string) string {
|
func (d SnowflakeDialect) QuotedTableForQuery(schema string, table string) string {
|
||||||
if strings.TrimSpace(schema) == "" {
|
if strings.TrimSpace(schema) == "" {
|
||||||
return d.QuoteField(table)
|
return d.QuoteField(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
return schema + "." + d.QuoteField(table)
|
return schema + "." + d.QuoteField(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) IfSchemaNotExists(command, schema string) string {
|
func (d SnowflakeDialect) IfSchemaNotExists(command, schema string) string {
|
||||||
return fmt.Sprintf("%s if not exists", command)
|
return fmt.Sprintf("%s if not exists", command)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) IfTableExists(command, schema, table string) string {
|
func (d SnowflakeDialect) IfTableExists(command, schema, table string) string {
|
||||||
return fmt.Sprintf("%s if exists", command)
|
return fmt.Sprintf("%s if exists", command)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d SnowflakeDialect) IfTableNotExists(command, schema, table string) string {
|
func (d SnowflakeDialect) IfTableNotExists(command, schema, table string) string {
|
||||||
return fmt.Sprintf("%s if not exists", command)
|
return fmt.Sprintf("%s if not exists", command)
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,10 +86,9 @@ func SelectNullStr(e SqlExecutor, query string, args ...interface{}) (sql.NullSt
|
||||||
// SelectOne executes the given query (which should be a SELECT statement)
|
// SelectOne executes the given query (which should be a SELECT statement)
|
||||||
// and binds the result to holder, which must be a pointer.
|
// and binds the result to holder, which must be a pointer.
|
||||||
//
|
//
|
||||||
// If no row is found, an error (sql.ErrNoRows specifically) will be returned
|
// # If no row is found, an error (sql.ErrNoRows specifically) will be returned
|
||||||
//
|
//
|
||||||
// If more than one row is found, an error will be returned.
|
// If more than one row is found, an error will be returned.
|
||||||
//
|
|
||||||
func SelectOne(m *DbMap, e SqlExecutor, holder interface{}, query string, args ...interface{}) error {
|
func SelectOne(m *DbMap, e SqlExecutor, holder interface{}, query string, args ...interface{}) error {
|
||||||
t := reflect.TypeOf(holder)
|
t := reflect.TypeOf(holder)
|
||||||
if t.Kind() == reflect.Ptr {
|
if t.Kind() == reflect.Ptr {
|
||||||
|
|
|
@ -47,7 +47,6 @@ func (t *TableMap) ResetSql() {
|
||||||
// Automatically calls ResetSql() to ensure SQL statements are regenerated.
|
// Automatically calls ResetSql() to ensure SQL statements are regenerated.
|
||||||
//
|
//
|
||||||
// Panics if isAutoIncr is true, and fieldNames length != 1
|
// Panics if isAutoIncr is true, and fieldNames length != 1
|
||||||
//
|
|
||||||
func (t *TableMap) SetKeys(isAutoIncr bool, fieldNames ...string) *TableMap {
|
func (t *TableMap) SetKeys(isAutoIncr bool, fieldNames ...string) *TableMap {
|
||||||
if isAutoIncr && len(fieldNames) != 1 {
|
if isAutoIncr && len(fieldNames) != 1 {
|
||||||
panic(fmt.Sprintf(
|
panic(fmt.Sprintf(
|
||||||
|
@ -73,7 +72,6 @@ func (t *TableMap) SetKeys(isAutoIncr bool, fieldNames ...string) *TableMap {
|
||||||
// Automatically calls ResetSql() to ensure SQL statements are regenerated.
|
// Automatically calls ResetSql() to ensure SQL statements are regenerated.
|
||||||
//
|
//
|
||||||
// Panics if fieldNames length < 2.
|
// Panics if fieldNames length < 2.
|
||||||
//
|
|
||||||
func (t *TableMap) SetUniqueTogether(fieldNames ...string) *TableMap {
|
func (t *TableMap) SetUniqueTogether(fieldNames ...string) *TableMap {
|
||||||
if len(fieldNames) < 2 {
|
if len(fieldNames) < 2 {
|
||||||
panic(fmt.Sprintf(
|
panic(fmt.Sprintf(
|
||||||
|
@ -135,7 +133,6 @@ func (t *TableMap) IdxMap(field string) *IndexMap {
|
||||||
// Function will panic if one of the given for index columns does not exists
|
// Function will panic if one of the given for index columns does not exists
|
||||||
//
|
//
|
||||||
// Automatically calls ResetSql() to ensure SQL statements are regenerated.
|
// Automatically calls ResetSql() to ensure SQL statements are regenerated.
|
||||||
//
|
|
||||||
func (t *TableMap) AddIndex(name string, idxtype string, columns []string) *IndexMap {
|
func (t *TableMap) AddIndex(name string, idxtype string, columns []string) *IndexMap {
|
||||||
// check if we have a index with this name already
|
// check if we have a index with this name already
|
||||||
for _, idx := range t.indexes {
|
for _, idx := range t.indexes {
|
||||||
|
|
|
@ -19,9 +19,10 @@ type DateRule struct {
|
||||||
// Date returns a validation rule that checks if a string value is in a format that can be parsed into a date.
|
// Date returns a validation rule that checks if a string value is in a format that can be parsed into a date.
|
||||||
// The format of the date should be specified as the layout parameter which accepts the same value as that for time.Parse.
|
// The format of the date should be specified as the layout parameter which accepts the same value as that for time.Parse.
|
||||||
// For example,
|
// For example,
|
||||||
// validation.Date(time.ANSIC)
|
//
|
||||||
// validation.Date("02 Jan 06 15:04 MST")
|
// validation.Date(time.ANSIC)
|
||||||
// validation.Date("2006-01-02")
|
// validation.Date("02 Jan 06 15:04 MST")
|
||||||
|
// validation.Date("2006-01-02")
|
||||||
//
|
//
|
||||||
// By calling Min() and/or Max(), you can let the Date rule to check if a parsed date value is within
|
// By calling Min() and/or Max(), you can let the Date rule to check if a parsed date value is within
|
||||||
// the specified date range.
|
// the specified date range.
|
||||||
|
|
|
@ -24,7 +24,6 @@ func (r *multipleOfRule) Error(message string) *multipleOfRule {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (r *multipleOfRule) Validate(value interface{}) error {
|
func (r *multipleOfRule) Validate(value interface{}) error {
|
||||||
|
|
||||||
rv := reflect.ValueOf(r.threshold)
|
rv := reflect.ValueOf(r.threshold)
|
||||||
|
|
|
@ -46,16 +46,16 @@ func (e ErrFieldNotFound) Error() string {
|
||||||
// should be specified as a pointer to the field. A field can be associated with multiple rules.
|
// should be specified as a pointer to the field. A field can be associated with multiple rules.
|
||||||
// For example,
|
// For example,
|
||||||
//
|
//
|
||||||
// value := struct {
|
// value := struct {
|
||||||
// Name string
|
// Name string
|
||||||
// Value string
|
// Value string
|
||||||
// }{"name", "demo"}
|
// }{"name", "demo"}
|
||||||
// err := validation.ValidateStruct(&value,
|
// err := validation.ValidateStruct(&value,
|
||||||
// validation.Field(&a.Name, validation.Required),
|
// validation.Field(&a.Name, validation.Required),
|
||||||
// validation.Field(&a.Value, validation.Required, validation.Length(5, 10)),
|
// validation.Field(&a.Value, validation.Required, validation.Length(5, 10)),
|
||||||
// )
|
// )
|
||||||
// fmt.Println(err)
|
// fmt.Println(err)
|
||||||
// // Value: the length must be between 5 and 10.
|
// // Value: the length must be between 5 and 10.
|
||||||
//
|
//
|
||||||
// An error will be returned if validation fails.
|
// An error will be returned if validation fails.
|
||||||
func ValidateStruct(structPtr interface{}, fields ...*FieldRules) error {
|
func ValidateStruct(structPtr interface{}, fields ...*FieldRules) error {
|
||||||
|
|
|
@ -41,10 +41,11 @@ type (
|
||||||
// Use Key() to specify map keys that need to be validated. Each Key() call specifies a single key which can
|
// Use Key() to specify map keys that need to be validated. Each Key() call specifies a single key which can
|
||||||
// be associated with multiple rules.
|
// be associated with multiple rules.
|
||||||
// For example,
|
// For example,
|
||||||
// validation.Map(
|
//
|
||||||
// validation.Key("Name", validation.Required),
|
// validation.Map(
|
||||||
// validation.Key("Value", validation.Required, validation.Length(5, 10)),
|
// validation.Key("Name", validation.Required),
|
||||||
// )
|
// validation.Key("Value", validation.Required, validation.Length(5, 10)),
|
||||||
|
// )
|
||||||
//
|
//
|
||||||
// A nil value is considered valid. Use the Required rule to make sure a map value is present.
|
// A nil value is considered valid. Use the Required rule to make sure a map value is present.
|
||||||
func Map(keys ...*KeyRules) MapRule {
|
func Map(keys ...*KeyRules) MapRule {
|
||||||
|
|
|
@ -47,16 +47,16 @@ func (e ErrFieldNotFound) Error() string {
|
||||||
// should be specified as a pointer to the field. A field can be associated with multiple rules.
|
// should be specified as a pointer to the field. A field can be associated with multiple rules.
|
||||||
// For example,
|
// For example,
|
||||||
//
|
//
|
||||||
// value := struct {
|
// value := struct {
|
||||||
// Name string
|
// Name string
|
||||||
// Value string
|
// Value string
|
||||||
// }{"name", "demo"}
|
// }{"name", "demo"}
|
||||||
// err := validation.ValidateStruct(&value,
|
// err := validation.ValidateStruct(&value,
|
||||||
// validation.Field(&a.Name, validation.Required),
|
// validation.Field(&a.Name, validation.Required),
|
||||||
// validation.Field(&a.Value, validation.Required, validation.Length(5, 10)),
|
// validation.Field(&a.Value, validation.Required, validation.Length(5, 10)),
|
||||||
// )
|
// )
|
||||||
// fmt.Println(err)
|
// fmt.Println(err)
|
||||||
// // Value: the length must be between 5 and 10.
|
// // Value: the length must be between 5 and 10.
|
||||||
//
|
//
|
||||||
// An error will be returned if validation fails.
|
// An error will be returned if validation fails.
|
||||||
func ValidateStruct(structPtr interface{}, fields ...*FieldRules) error {
|
func ValidateStruct(structPtr interface{}, fields ...*FieldRules) error {
|
||||||
|
|
|
@ -60,11 +60,11 @@ var (
|
||||||
// Validate validates the given value and returns the validation error, if any.
|
// Validate validates the given value and returns the validation error, if any.
|
||||||
//
|
//
|
||||||
// Validate performs validation using the following steps:
|
// Validate performs validation using the following steps:
|
||||||
// 1. For each rule, call its `Validate()` to validate the value. Return if any error is found.
|
// 1. For each rule, call its `Validate()` to validate the value. Return if any error is found.
|
||||||
// 2. If the value being validated implements `Validatable`, call the value's `Validate()`.
|
// 2. If the value being validated implements `Validatable`, call the value's `Validate()`.
|
||||||
// Return with the validation result.
|
// Return with the validation result.
|
||||||
// 3. If the value being validated is a map/slice/array, and the element type implements `Validatable`,
|
// 3. If the value being validated is a map/slice/array, and the element type implements `Validatable`,
|
||||||
// for each element call the element value's `Validate()`. Return with the validation result.
|
// for each element call the element value's `Validate()`. Return with the validation result.
|
||||||
func Validate(value interface{}, rules ...Rule) error {
|
func Validate(value interface{}, rules ...Rule) error {
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
if s, ok := rule.(skipRule); ok && s.skip {
|
if s, ok := rule.(skipRule); ok && s.skip {
|
||||||
|
@ -103,16 +103,16 @@ func Validate(value interface{}, rules ...Rule) error {
|
||||||
// ValidateWithContext validates the given value with the given context and returns the validation error, if any.
|
// ValidateWithContext validates the given value with the given context and returns the validation error, if any.
|
||||||
//
|
//
|
||||||
// ValidateWithContext performs validation using the following steps:
|
// ValidateWithContext performs validation using the following steps:
|
||||||
// 1. For each rule, call its `ValidateWithContext()` to validate the value if the rule implements `RuleWithContext`.
|
// 1. For each rule, call its `ValidateWithContext()` to validate the value if the rule implements `RuleWithContext`.
|
||||||
// Otherwise call `Validate()` of the rule. Return if any error is found.
|
// Otherwise call `Validate()` of the rule. Return if any error is found.
|
||||||
// 2. If the value being validated implements `ValidatableWithContext`, call the value's `ValidateWithContext()`
|
// 2. If the value being validated implements `ValidatableWithContext`, call the value's `ValidateWithContext()`
|
||||||
// and return with the validation result.
|
// and return with the validation result.
|
||||||
// 3. If the value being validated implements `Validatable`, call the value's `Validate()`
|
// 3. If the value being validated implements `Validatable`, call the value's `Validate()`
|
||||||
// and return with the validation result.
|
// and return with the validation result.
|
||||||
// 4. If the value being validated is a map/slice/array, and the element type implements `ValidatableWithContext`,
|
// 4. If the value being validated is a map/slice/array, and the element type implements `ValidatableWithContext`,
|
||||||
// for each element call the element value's `ValidateWithContext()`. Return with the validation result.
|
// for each element call the element value's `ValidateWithContext()`. Return with the validation result.
|
||||||
// 5. If the value being validated is a map/slice/array, and the element type implements `Validatable`,
|
// 5. If the value being validated is a map/slice/array, and the element type implements `Validatable`,
|
||||||
// for each element call the element value's `Validate()`. Return with the validation result.
|
// for each element call the element value's `Validate()`. Return with the validation result.
|
||||||
func ValidateWithContext(ctx context.Context, value interface{}, rules ...Rule) error {
|
func ValidateWithContext(ctx context.Context, value interface{}, rules ...Rule) error {
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
if s, ok := rule.(skipRule); ok && s.skip {
|
if s, ok := rule.(skipRule); ok && s.skip {
|
||||||
|
|
|
@ -33,27 +33,26 @@ var (
|
||||||
// Note: The provided rsa.PublicKey instance is exclusively owned by the driver
|
// Note: The provided rsa.PublicKey instance is exclusively owned by the driver
|
||||||
// after registering it and may not be modified.
|
// after registering it and may not be modified.
|
||||||
//
|
//
|
||||||
// data, err := ioutil.ReadFile("mykey.pem")
|
// data, err := ioutil.ReadFile("mykey.pem")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// block, _ := pem.Decode(data)
|
// block, _ := pem.Decode(data)
|
||||||
// if block == nil || block.Type != "PUBLIC KEY" {
|
// if block == nil || block.Type != "PUBLIC KEY" {
|
||||||
// log.Fatal("failed to decode PEM block containing public key")
|
// log.Fatal("failed to decode PEM block containing public key")
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// pub, err := x509.ParsePKIXPublicKey(block.Bytes)
|
// pub, err := x509.ParsePKIXPublicKey(block.Bytes)
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
//
|
|
||||||
// if rsaPubKey, ok := pub.(*rsa.PublicKey); ok {
|
|
||||||
// mysql.RegisterServerPubKey("mykey", rsaPubKey)
|
|
||||||
// } else {
|
|
||||||
// log.Fatal("not a RSA public key")
|
|
||||||
// }
|
|
||||||
//
|
//
|
||||||
|
// if rsaPubKey, ok := pub.(*rsa.PublicKey); ok {
|
||||||
|
// mysql.RegisterServerPubKey("mykey", rsaPubKey)
|
||||||
|
// } else {
|
||||||
|
// log.Fatal("not a RSA public key")
|
||||||
|
// }
|
||||||
func RegisterServerPubKey(name string, pubKey *rsa.PublicKey) {
|
func RegisterServerPubKey(name string, pubKey *rsa.PublicKey) {
|
||||||
serverPubKeyLock.Lock()
|
serverPubKeyLock.Lock()
|
||||||
if serverPubKeyRegistry == nil {
|
if serverPubKeyRegistry == nil {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||||
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
// You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
//go:build linux || darwin || dragonfly || freebsd || netbsd || openbsd || solaris || illumos
|
||||||
// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos
|
// +build linux darwin dragonfly freebsd netbsd openbsd solaris illumos
|
||||||
|
|
||||||
package mysql
|
package mysql
|
||||||
|
|
|
@ -8,10 +8,10 @@
|
||||||
//
|
//
|
||||||
// The driver should be used via the database/sql package:
|
// The driver should be used via the database/sql package:
|
||||||
//
|
//
|
||||||
// import "database/sql"
|
// import "database/sql"
|
||||||
// import _ "github.com/go-sql-driver/mysql"
|
// import _ "github.com/go-sql-driver/mysql"
|
||||||
//
|
//
|
||||||
// db, err := sql.Open("mysql", "user:password@/dbname")
|
// db, err := sql.Open("mysql", "user:password@/dbname")
|
||||||
//
|
//
|
||||||
// See https://github.com/go-sql-driver/mysql#usage for details
|
// See https://github.com/go-sql-driver/mysql#usage for details
|
||||||
package mysql
|
package mysql
|
||||||
|
|
|
@ -28,12 +28,11 @@ var (
|
||||||
// Alternatively you can allow the use of all local files with
|
// Alternatively you can allow the use of all local files with
|
||||||
// the DSN parameter 'allowAllFiles=true'
|
// the DSN parameter 'allowAllFiles=true'
|
||||||
//
|
//
|
||||||
// filePath := "/home/gopher/data.csv"
|
// filePath := "/home/gopher/data.csv"
|
||||||
// mysql.RegisterLocalFile(filePath)
|
// mysql.RegisterLocalFile(filePath)
|
||||||
// err := db.Exec("LOAD DATA LOCAL INFILE '" + filePath + "' INTO TABLE foo")
|
// err := db.Exec("LOAD DATA LOCAL INFILE '" + filePath + "' INTO TABLE foo")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// ...
|
// ...
|
||||||
//
|
|
||||||
func RegisterLocalFile(filePath string) {
|
func RegisterLocalFile(filePath string) {
|
||||||
fileRegisterLock.Lock()
|
fileRegisterLock.Lock()
|
||||||
// lazy map init
|
// lazy map init
|
||||||
|
@ -58,15 +57,14 @@ func DeregisterLocalFile(filePath string) {
|
||||||
// If the handler returns a io.ReadCloser Close() is called when the
|
// If the handler returns a io.ReadCloser Close() is called when the
|
||||||
// request is finished.
|
// request is finished.
|
||||||
//
|
//
|
||||||
// mysql.RegisterReaderHandler("data", func() io.Reader {
|
// mysql.RegisterReaderHandler("data", func() io.Reader {
|
||||||
// var csvReader io.Reader // Some Reader that returns CSV data
|
// var csvReader io.Reader // Some Reader that returns CSV data
|
||||||
// ... // Open Reader here
|
// ... // Open Reader here
|
||||||
// return csvReader
|
// return csvReader
|
||||||
// })
|
// })
|
||||||
// err := db.Exec("LOAD DATA LOCAL INFILE 'Reader::data' INTO TABLE foo")
|
// err := db.Exec("LOAD DATA LOCAL INFILE 'Reader::data' INTO TABLE foo")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// ...
|
// ...
|
||||||
//
|
|
||||||
func RegisterReaderHandler(name string, handler func() io.Reader) {
|
func RegisterReaderHandler(name string, handler func() io.Reader) {
|
||||||
readerRegisterLock.Lock()
|
readerRegisterLock.Lock()
|
||||||
// lazy map init
|
// lazy map init
|
||||||
|
|
|
@ -35,26 +35,25 @@ var (
|
||||||
// Note: The provided tls.Config is exclusively owned by the driver after
|
// Note: The provided tls.Config is exclusively owned by the driver after
|
||||||
// registering it.
|
// registering it.
|
||||||
//
|
//
|
||||||
// rootCertPool := x509.NewCertPool()
|
// rootCertPool := x509.NewCertPool()
|
||||||
// pem, err := ioutil.ReadFile("/path/ca-cert.pem")
|
// pem, err := ioutil.ReadFile("/path/ca-cert.pem")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
// if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
|
// if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
|
||||||
// log.Fatal("Failed to append PEM.")
|
// log.Fatal("Failed to append PEM.")
|
||||||
// }
|
// }
|
||||||
// clientCert := make([]tls.Certificate, 0, 1)
|
// clientCert := make([]tls.Certificate, 0, 1)
|
||||||
// certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
|
// certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
|
||||||
// if err != nil {
|
// if err != nil {
|
||||||
// log.Fatal(err)
|
// log.Fatal(err)
|
||||||
// }
|
// }
|
||||||
// clientCert = append(clientCert, certs)
|
// clientCert = append(clientCert, certs)
|
||||||
// mysql.RegisterTLSConfig("custom", &tls.Config{
|
// mysql.RegisterTLSConfig("custom", &tls.Config{
|
||||||
// RootCAs: rootCertPool,
|
// RootCAs: rootCertPool,
|
||||||
// Certificates: clientCert,
|
// Certificates: clientCert,
|
||||||
// })
|
// })
|
||||||
// db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
|
// db, err := sql.Open("mysql", "user@tcp(localhost:3306)/test?tls=custom")
|
||||||
//
|
|
||||||
func RegisterTLSConfig(key string, config *tls.Config) error {
|
func RegisterTLSConfig(key string, config *tls.Config) error {
|
||||||
if _, isBool := readBool(key); isBool || strings.ToLower(key) == "skip-verify" || strings.ToLower(key) == "preferred" {
|
if _, isBool := readBool(key); isBool || strings.ToLower(key) == "skip-verify" || strings.ToLower(key) == "preferred" {
|
||||||
return fmt.Errorf("key '%s' is reserved", key)
|
return fmt.Errorf("key '%s' is reserved", key)
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
package jwt
|
package jwt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -3,7 +3,6 @@ package jwt
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
// "fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Claims type that uses the map[string]interface{} for JSON decoding
|
// Claims type that uses the map[string]interface{} for JSON decoding
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build go1.4
|
||||||
// +build go1.4
|
// +build go1.4
|
||||||
|
|
||||||
package jwt
|
package jwt
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package jwt
|
package jwt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
// "fmt"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// MapClaims is a claims type that uses the map[string]interface{} for JSON decoding.
|
// MapClaims is a claims type that uses the map[string]interface{} for JSON decoding.
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
package jwt
|
package jwt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"crypto"
|
"crypto"
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -5,20 +5,20 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//MessageCountInbox ...
|
// MessageCountInbox ...
|
||||||
type MessageCountInbox struct {
|
type MessageCountInbox struct {
|
||||||
Startdate int `json:"startdate"`
|
Startdate int `json:"startdate"`
|
||||||
Enddate int `json:"enddate"`
|
Enddate int `json:"enddate"`
|
||||||
Sumcount int `json:"sumcount"`
|
Sumcount int `json:"sumcount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//MessageCountInboxResult ...
|
// MessageCountInboxResult ...
|
||||||
type MessageCountInboxResult struct {
|
type MessageCountInboxResult struct {
|
||||||
*Return `json:"return"`
|
*Return `json:"return"`
|
||||||
Entries []MessageCountInbox `json:"entries"`
|
Entries []MessageCountInbox `json:"entries"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//CountInbox ...
|
// CountInbox ...
|
||||||
func (message *MessageService) CountInbox(linenumber string, startdate time.Time, endate time.Time, isread bool) (MessageCountInbox, error) {
|
func (message *MessageService) CountInbox(linenumber string, startdate time.Time, endate time.Time, isread bool) (MessageCountInbox, error) {
|
||||||
|
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
|
@ -33,13 +33,13 @@ func (message *MessageService) CountInbox(linenumber string, startdate time.Time
|
||||||
return message.CreateCountInbox(v)
|
return message.CreateCountInbox(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
//CreateCountInbox ...
|
// CreateCountInbox ...
|
||||||
func (message *MessageService) CreateCountInbox(v url.Values) (MessageCountInbox, error) {
|
func (message *MessageService) CreateCountInbox(v url.Values) (MessageCountInbox, error) {
|
||||||
u := message.client.EndPoint("sms", "countinbox")
|
u := message.client.EndPoint("sms", "countinbox")
|
||||||
m := new(MessageCountInboxResult)
|
m := new(MessageCountInboxResult)
|
||||||
err := message.client.Execute(u.String(), v, m)
|
err := message.client.Execute(u.String(), v, m)
|
||||||
if m.Entries==nil{
|
if m.Entries == nil {
|
||||||
return MessageCountInbox{},err
|
return MessageCountInbox{}, err
|
||||||
}
|
}
|
||||||
return m.Entries[0], err
|
return m.Entries[0], err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,19 +5,19 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
//MessageCountPostalCode ...
|
// MessageCountPostalCode ...
|
||||||
type MessageCountPostalCode struct {
|
type MessageCountPostalCode struct {
|
||||||
Section string `json:"section"`
|
Section string `json:"section"`
|
||||||
Value int `json:"value"`
|
Value int `json:"value"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//MessageCountPostalCodeResult ...
|
// MessageCountPostalCodeResult ...
|
||||||
type MessageCountPostalCodeResult struct {
|
type MessageCountPostalCodeResult struct {
|
||||||
*Return `json:"return"`
|
*Return `json:"return"`
|
||||||
Entries []MessageCountPostalCode `json:"entries"`
|
Entries []MessageCountPostalCode `json:"entries"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//CountPostalCode ...
|
// CountPostalCode ...
|
||||||
func (message *MessageService) CountPostalCode(postalcode int64) ([]MessageCountPostalCode, error) {
|
func (message *MessageService) CountPostalCode(postalcode int64) ([]MessageCountPostalCode, error) {
|
||||||
u := message.client.EndPoint("sms", "countpostalcode")
|
u := message.client.EndPoint("sms", "countpostalcode")
|
||||||
m := new(MessageCountPostalCodeResult)
|
m := new(MessageCountPostalCodeResult)
|
||||||
|
|
|
@ -5,20 +5,20 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//MessageCountOutbox ...
|
// MessageCountOutbox ...
|
||||||
type MessageCountOutbox struct {
|
type MessageCountOutbox struct {
|
||||||
*MessageCountInbox
|
*MessageCountInbox
|
||||||
Sumpart int `json:"sumpart"`
|
Sumpart int `json:"sumpart"`
|
||||||
Cost int `json:"cost"`
|
Cost int `json:"cost"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//MessageCountOutboxResult ...
|
// MessageCountOutboxResult ...
|
||||||
type MessageCountOutboxResult struct {
|
type MessageCountOutboxResult struct {
|
||||||
*Return `json:"return"`
|
*Return `json:"return"`
|
||||||
Entries []MessageCountOutbox `json:"entries"`
|
Entries []MessageCountOutbox `json:"entries"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//CountOutbox ...
|
// CountOutbox ...
|
||||||
func (message *MessageService) CountOutbox(startdate time.Time, endate time.Time, status MessageStatusType) (MessageCountOutbox, error) {
|
func (message *MessageService) CountOutbox(startdate time.Time, endate time.Time, status MessageStatusType) (MessageCountOutbox, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("startdate", ToUnix(startdate))
|
v.Set("startdate", ToUnix(startdate))
|
||||||
|
@ -29,13 +29,13 @@ func (message *MessageService) CountOutbox(startdate time.Time, endate time.Time
|
||||||
return message.CreateCountOutbox(v)
|
return message.CreateCountOutbox(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
//CreateCountOutbox ...
|
// CreateCountOutbox ...
|
||||||
func (message *MessageService) CreateCountOutbox(v url.Values) (MessageCountOutbox, error) {
|
func (message *MessageService) CreateCountOutbox(v url.Values) (MessageCountOutbox, error) {
|
||||||
u := message.client.EndPoint("sms", "countoutbox")
|
u := message.client.EndPoint("sms", "countoutbox")
|
||||||
m := new(MessageCountOutboxResult)
|
m := new(MessageCountOutboxResult)
|
||||||
err := message.client.Execute(u.String(), v, m)
|
err := message.client.Execute(u.String(), v, m)
|
||||||
if m.Entries==nil{
|
if m.Entries == nil {
|
||||||
return MessageCountOutbox{},err
|
return MessageCountOutbox{}, err
|
||||||
}
|
}
|
||||||
return m.Entries[0], err
|
return m.Entries[0], err
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
//LatestOutbox ...
|
// LatestOutbox ...
|
||||||
func (message *MessageService) LatestOutbox(sender string, pagesize int) ([]Message, error) {
|
func (message *MessageService) LatestOutbox(sender string, pagesize int) ([]Message, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("sender", sender)
|
v.Set("sender", sender)
|
||||||
|
@ -13,7 +13,7 @@ func (message *MessageService) LatestOutbox(sender string, pagesize int) ([]Mess
|
||||||
return message.CreateLatestOutbox(v)
|
return message.CreateLatestOutbox(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
//CreateLatestOutbox ...
|
// CreateLatestOutbox ...
|
||||||
func (message *MessageService) CreateLatestOutbox(v url.Values) ([]Message, error) {
|
func (message *MessageService) CreateLatestOutbox(v url.Values) ([]Message, error) {
|
||||||
u := message.client.EndPoint("sms", "latestoutbox")
|
u := message.client.EndPoint("sms", "latestoutbox")
|
||||||
vc := url.Values{}
|
vc := url.Values{}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//SelectOutbox ...
|
// SelectOutbox ...
|
||||||
func (message *MessageService) SelectOutbox(startdate time.Time, endate time.Time, sender string) ([]Message, error) {
|
func (message *MessageService) SelectOutbox(startdate time.Time, endate time.Time, sender string) ([]Message, error) {
|
||||||
|
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
|
@ -23,7 +23,7 @@ func (message *MessageService) SelectOutbox(startdate time.Time, endate time.Tim
|
||||||
return message.CreateSelectOutbox(v)
|
return message.CreateSelectOutbox(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
//CreateSelectOutbox ...
|
// CreateSelectOutbox ...
|
||||||
func (message *MessageService) CreateSelectOutbox(v url.Values) ([]Message, error) {
|
func (message *MessageService) CreateSelectOutbox(v url.Values) ([]Message, error) {
|
||||||
u := message.client.EndPoint("sms", "selectoutbox")
|
u := message.client.EndPoint("sms", "selectoutbox")
|
||||||
m := new(MessageResult)
|
m := new(MessageResult)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//SendPostalCode ...
|
// SendPostalCode ...
|
||||||
func (m *MessageService) SendPostalCode(postalcode int64, sender string, message string, mcistartindex int, mcicount int, mtnstartindex int, mtncount int, date time.Time) ([]Message, error) {
|
func (m *MessageService) SendPostalCode(postalcode int64, sender string, message string, mcistartindex int, mcicount int, mtnstartindex int, mtncount int, date time.Time) ([]Message, error) {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("postalcode", strconv.FormatInt(postalcode, 10))
|
v.Set("postalcode", strconv.FormatInt(postalcode, 10))
|
||||||
|
@ -20,9 +20,9 @@ func (m *MessageService) SendPostalCode(postalcode int64, sender string, message
|
||||||
return m.CreateSendPostalCode(v)
|
return m.CreateSendPostalCode(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
//CreateSendPostalCode ...
|
// CreateSendPostalCode ...
|
||||||
func (m *MessageService) CreateSendPostalCode(v url.Values) ([]Message, error) {
|
func (m *MessageService) CreateSendPostalCode(v url.Values) ([]Message, error) {
|
||||||
u := m.client.EndPoint("sms", "sendbypostalcode")
|
u := m.client.EndPoint("sms", "sendbypostalcode")
|
||||||
res := new(MessageResult)
|
res := new(MessageResult)
|
||||||
err := m.client.Execute(u.String(), v, res)
|
err := m.client.Execute(u.String(), v, res)
|
||||||
return res.Entries, err
|
return res.Entries, err
|
||||||
|
|
|
@ -5,26 +5,26 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
//MessageStatusLocal ...
|
// MessageStatusLocal ...
|
||||||
type MessageStatusLocal struct {
|
type MessageStatusLocal struct {
|
||||||
*MessageStatus
|
*MessageStatus
|
||||||
LocalID string `json:"localid"`
|
LocalID string `json:"localid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//MessageStatusLocalResult ...
|
// MessageStatusLocalResult ...
|
||||||
type MessageStatusLocalResult struct {
|
type MessageStatusLocalResult struct {
|
||||||
*Return `json:"return"`
|
*Return `json:"return"`
|
||||||
Entries []MessageStatusLocal `json:"entries"`
|
Entries []MessageStatusLocal `json:"entries"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//StatusLocal ...
|
// StatusLocal ...
|
||||||
func (message *MessageService) StatusLocal(localid int64) (MessageStatusLocal, error) {
|
func (message *MessageService) StatusLocal(localid int64) (MessageStatusLocal, error) {
|
||||||
u := message.client.EndPoint("sms", "statuslocalmessageid")
|
u := message.client.EndPoint("sms", "statuslocalmessageid")
|
||||||
m := new(MessageStatusLocalResult)
|
m := new(MessageStatusLocalResult)
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
v.Set("localid", strconv.FormatInt(localid, 10))
|
v.Set("localid", strconv.FormatInt(localid, 10))
|
||||||
err := message.client.Execute(u.String(), v, m)
|
err := message.client.Execute(u.String(), v, m)
|
||||||
if err!=nil{
|
if err != nil {
|
||||||
return MessageStatusLocal{}, err
|
return MessageStatusLocal{}, err
|
||||||
}
|
}
|
||||||
return m.Entries[0], err
|
return m.Entries[0], err
|
||||||
|
|
|
@ -10,23 +10,23 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
//ToString ...
|
// ToString ...
|
||||||
func ToString(i interface{}) string {
|
func ToString(i interface{}) string {
|
||||||
return strings.Trim(strings.Replace(fmt.Sprint(i), " ", ",", -1), "[]")
|
return strings.Trim(strings.Replace(fmt.Sprint(i), " ", ",", -1), "[]")
|
||||||
}
|
}
|
||||||
|
|
||||||
//ToJson ...
|
// ToJson ...
|
||||||
func ToJson(i interface{}) string {
|
func ToJson(i interface{}) string {
|
||||||
_json, _ := json.Marshal(i)
|
_json, _ := json.Marshal(i)
|
||||||
return string(_json)
|
return string(_json)
|
||||||
}
|
}
|
||||||
|
|
||||||
//ToUnix ...
|
// ToUnix ...
|
||||||
func ToUnix(t time.Time) string {
|
func ToUnix(t time.Time) string {
|
||||||
return strconv.FormatInt(t.Unix(), 10)
|
return strconv.FormatInt(t.Unix(), 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
//structToUrlValues ...
|
// structToUrlValues ...
|
||||||
func structToURLValues(i interface{}) url.Values {
|
func structToURLValues(i interface{}) url.Values {
|
||||||
v := url.Values{}
|
v := url.Values{}
|
||||||
if reflect.ValueOf(i).IsNil() {
|
if reflect.ValueOf(i).IsNil() {
|
||||||
|
|
|
@ -5,9 +5,10 @@ package maps
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/copystructure"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mitchellh/copystructure"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flatten takes a map[string]interface{} and traverses it and flattens
|
// Flatten takes a map[string]interface{} and traverses it and flattens
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/fatih/structs"
|
"github.com/fatih/structs"
|
||||||
|
|
||||||
"github.com/knadh/koanf/maps"
|
"github.com/knadh/koanf/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,11 @@ package echojwt
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"github.com/labstack/echo/v4/middleware"
|
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/labstack/echo/v4/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -4,8 +4,9 @@
|
||||||
package echo
|
package echo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/labstack/gommon/log"
|
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/labstack/gommon/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Logger defines the logging interface.
|
// Logger defines the logging interface.
|
||||||
|
|
|
@ -6,9 +6,10 @@ package middleware
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -9,10 +9,11 @@ package middleware
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang-jwt/jwt"
|
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
|
"github.com/golang-jwt/jwt"
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
// JWTConfig defines the config for JWT middleware.
|
// JWTConfig defines the config for JWT middleware.
|
||||||
|
|
|
@ -5,8 +5,9 @@ package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KeyAuthConfig defines the config for KeyAuth middleware.
|
// KeyAuthConfig defines the config for KeyAuth middleware.
|
||||||
|
|
|
@ -5,10 +5,11 @@ package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/labstack/echo/v4"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/labstack/echo/v4"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build !appengine
|
||||||
// +build !appengine
|
// +build !appengine
|
||||||
|
|
||||||
package log
|
package log
|
||||||
|
|
|
@ -13,10 +13,9 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/labstack/gommon/color"
|
||||||
"github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
"github.com/valyala/fasttemplate"
|
"github.com/valyala/fasttemplate"
|
||||||
|
|
||||||
"github.com/labstack/gommon/color"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
//go:build appengine
|
||||||
// +build appengine
|
// +build appengine
|
||||||
|
|
||||||
package log
|
package log
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
// easyjson_nounsafe nor appengine build tag is set. See README notes
|
// easyjson_nounsafe nor appengine build tag is set. See README notes
|
||||||
// for more details.
|
// for more details.
|
||||||
|
|
||||||
//+build !easyjson_nounsafe
|
//go:build !easyjson_nounsafe && !appengine
|
||||||
//+build !appengine
|
// +build !easyjson_nounsafe,!appengine
|
||||||
|
|
||||||
package jlexer
|
package jlexer
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,8 @@ func IsTerminal(fd uintptr) bool {
|
||||||
|
|
||||||
// Check pipe name is used for cygwin/msys2 pty.
|
// Check pipe name is used for cygwin/msys2 pty.
|
||||||
// Cygwin/MSYS2 PTY has a name like:
|
// Cygwin/MSYS2 PTY has a name like:
|
||||||
// \{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master
|
//
|
||||||
|
// \{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master
|
||||||
func isCygwinPipeName(name string) bool {
|
func isCygwinPipeName(name string) bool {
|
||||||
token := strings.Split(name, "-")
|
token := strings.Split(name, "-")
|
||||||
if len(token) < 5 {
|
if len(token) < 5 {
|
||||||
|
|
|
@ -18,20 +18,19 @@ const tagKey = "copy"
|
||||||
//
|
//
|
||||||
// For structs, copy behavior can be controlled with struct tags. For example:
|
// For structs, copy behavior can be controlled with struct tags. For example:
|
||||||
//
|
//
|
||||||
// struct {
|
// struct {
|
||||||
// Name string
|
// Name string
|
||||||
// Data *bytes.Buffer `copy:"shallow"`
|
// Data *bytes.Buffer `copy:"shallow"`
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// The available tag values are:
|
// The available tag values are:
|
||||||
//
|
//
|
||||||
// * "ignore" - The field will be ignored, effectively resulting in it being
|
// - "ignore" - The field will be ignored, effectively resulting in it being
|
||||||
// assigned the zero value in the copy.
|
// assigned the zero value in the copy.
|
||||||
//
|
|
||||||
// * "shallow" - The field will be be shallow copied. This means that references
|
|
||||||
// values such as pointers, maps, slices, etc. will be directly assigned
|
|
||||||
// versus deep copied.
|
|
||||||
//
|
//
|
||||||
|
// - "shallow" - The field will be be shallow copied. This means that references
|
||||||
|
// values such as pointers, maps, slices, etc. will be directly assigned
|
||||||
|
// versus deep copied.
|
||||||
func Copy(v interface{}) (interface{}, error) {
|
func Copy(v interface{}) (interface{}, error) {
|
||||||
return Config{}.Copy(v)
|
return Config{}.Copy(v)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,84 +9,84 @@
|
||||||
//
|
//
|
||||||
// The simplest function to start with is Decode.
|
// The simplest function to start with is Decode.
|
||||||
//
|
//
|
||||||
// Field Tags
|
// # Field Tags
|
||||||
//
|
//
|
||||||
// When decoding to a struct, mapstructure will use the field name by
|
// When decoding to a struct, mapstructure will use the field name by
|
||||||
// default to perform the mapping. For example, if a struct has a field
|
// default to perform the mapping. For example, if a struct has a field
|
||||||
// "Username" then mapstructure will look for a key in the source value
|
// "Username" then mapstructure will look for a key in the source value
|
||||||
// of "username" (case insensitive).
|
// of "username" (case insensitive).
|
||||||
//
|
//
|
||||||
// type User struct {
|
// type User struct {
|
||||||
// Username string
|
// Username string
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// You can change the behavior of mapstructure by using struct tags.
|
// You can change the behavior of mapstructure by using struct tags.
|
||||||
// The default struct tag that mapstructure looks for is "mapstructure"
|
// The default struct tag that mapstructure looks for is "mapstructure"
|
||||||
// but you can customize it using DecoderConfig.
|
// but you can customize it using DecoderConfig.
|
||||||
//
|
//
|
||||||
// Renaming Fields
|
// # Renaming Fields
|
||||||
//
|
//
|
||||||
// To rename the key that mapstructure looks for, use the "mapstructure"
|
// To rename the key that mapstructure looks for, use the "mapstructure"
|
||||||
// tag and set a value directly. For example, to change the "username" example
|
// tag and set a value directly. For example, to change the "username" example
|
||||||
// above to "user":
|
// above to "user":
|
||||||
//
|
//
|
||||||
// type User struct {
|
// type User struct {
|
||||||
// Username string `mapstructure:"user"`
|
// Username string `mapstructure:"user"`
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Embedded Structs and Squashing
|
// # Embedded Structs and Squashing
|
||||||
//
|
//
|
||||||
// Embedded structs are treated as if they're another field with that name.
|
// Embedded structs are treated as if they're another field with that name.
|
||||||
// By default, the two structs below are equivalent when decoding with
|
// By default, the two structs below are equivalent when decoding with
|
||||||
// mapstructure:
|
// mapstructure:
|
||||||
//
|
//
|
||||||
// type Person struct {
|
// type Person struct {
|
||||||
// Name string
|
// Name string
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// type Friend struct {
|
// type Friend struct {
|
||||||
// Person
|
// Person
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// type Friend struct {
|
// type Friend struct {
|
||||||
// Person Person
|
// Person Person
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// This would require an input that looks like below:
|
// This would require an input that looks like below:
|
||||||
//
|
//
|
||||||
// map[string]interface{}{
|
// map[string]interface{}{
|
||||||
// "person": map[string]interface{}{"name": "alice"},
|
// "person": map[string]interface{}{"name": "alice"},
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// If your "person" value is NOT nested, then you can append ",squash" to
|
// If your "person" value is NOT nested, then you can append ",squash" to
|
||||||
// your tag value and mapstructure will treat it as if the embedded struct
|
// your tag value and mapstructure will treat it as if the embedded struct
|
||||||
// were part of the struct directly. Example:
|
// were part of the struct directly. Example:
|
||||||
//
|
//
|
||||||
// type Friend struct {
|
// type Friend struct {
|
||||||
// Person `mapstructure:",squash"`
|
// Person `mapstructure:",squash"`
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Now the following input would be accepted:
|
// Now the following input would be accepted:
|
||||||
//
|
//
|
||||||
// map[string]interface{}{
|
// map[string]interface{}{
|
||||||
// "name": "alice",
|
// "name": "alice",
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// When decoding from a struct to a map, the squash tag squashes the struct
|
// When decoding from a struct to a map, the squash tag squashes the struct
|
||||||
// fields into a single map. Using the example structs from above:
|
// fields into a single map. Using the example structs from above:
|
||||||
//
|
//
|
||||||
// Friend{Person: Person{Name: "alice"}}
|
// Friend{Person: Person{Name: "alice"}}
|
||||||
//
|
//
|
||||||
// Will be decoded into a map:
|
// Will be decoded into a map:
|
||||||
//
|
//
|
||||||
// map[string]interface{}{
|
// map[string]interface{}{
|
||||||
// "name": "alice",
|
// "name": "alice",
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// DecoderConfig has a field that changes the behavior of mapstructure
|
// DecoderConfig has a field that changes the behavior of mapstructure
|
||||||
// to always squash embedded structs.
|
// to always squash embedded structs.
|
||||||
//
|
//
|
||||||
// Remainder Values
|
// # Remainder Values
|
||||||
//
|
//
|
||||||
// If there are any unmapped keys in the source value, mapstructure by
|
// If there are any unmapped keys in the source value, mapstructure by
|
||||||
// default will silently ignore them. You can error by setting ErrorUnused
|
// default will silently ignore them. You can error by setting ErrorUnused
|
||||||
|
@ -98,20 +98,20 @@
|
||||||
// probably be a "map[string]interface{}" or "map[interface{}]interface{}".
|
// probably be a "map[string]interface{}" or "map[interface{}]interface{}".
|
||||||
// See example below:
|
// See example below:
|
||||||
//
|
//
|
||||||
// type Friend struct {
|
// type Friend struct {
|
||||||
// Name string
|
// Name string
|
||||||
// Other map[string]interface{} `mapstructure:",remain"`
|
// Other map[string]interface{} `mapstructure:",remain"`
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Given the input below, Other would be populated with the other
|
// Given the input below, Other would be populated with the other
|
||||||
// values that weren't used (everything but "name"):
|
// values that weren't used (everything but "name"):
|
||||||
//
|
//
|
||||||
// map[string]interface{}{
|
// map[string]interface{}{
|
||||||
// "name": "bob",
|
// "name": "bob",
|
||||||
// "address": "123 Maple St.",
|
// "address": "123 Maple St.",
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Omit Empty Values
|
// # Omit Empty Values
|
||||||
//
|
//
|
||||||
// When decoding from a struct to any other value, you may use the
|
// When decoding from a struct to any other value, you may use the
|
||||||
// ",omitempty" suffix on your tag to omit that value if it equates to
|
// ",omitempty" suffix on your tag to omit that value if it equates to
|
||||||
|
@ -122,37 +122,37 @@
|
||||||
// field value is zero and a numeric type, the field is empty, and it won't
|
// field value is zero and a numeric type, the field is empty, and it won't
|
||||||
// be encoded into the destination type.
|
// be encoded into the destination type.
|
||||||
//
|
//
|
||||||
// type Source struct {
|
// type Source struct {
|
||||||
// Age int `mapstructure:",omitempty"`
|
// Age int `mapstructure:",omitempty"`
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Unexported fields
|
// # Unexported fields
|
||||||
//
|
//
|
||||||
// Since unexported (private) struct fields cannot be set outside the package
|
// Since unexported (private) struct fields cannot be set outside the package
|
||||||
// where they are defined, the decoder will simply skip them.
|
// where they are defined, the decoder will simply skip them.
|
||||||
//
|
//
|
||||||
// For this output type definition:
|
// For this output type definition:
|
||||||
//
|
//
|
||||||
// type Exported struct {
|
// type Exported struct {
|
||||||
// private string // this unexported field will be skipped
|
// private string // this unexported field will be skipped
|
||||||
// Public string
|
// Public string
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Using this map as input:
|
// Using this map as input:
|
||||||
//
|
//
|
||||||
// map[string]interface{}{
|
// map[string]interface{}{
|
||||||
// "private": "I will be ignored",
|
// "private": "I will be ignored",
|
||||||
// "Public": "I made it through!",
|
// "Public": "I made it through!",
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// The following struct will be decoded:
|
// The following struct will be decoded:
|
||||||
//
|
//
|
||||||
// type Exported struct {
|
// type Exported struct {
|
||||||
// private: "" // field is left with an empty string (zero value)
|
// private: "" // field is left with an empty string (zero value)
|
||||||
// Public: "I made it through!"
|
// Public: "I made it through!"
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// Other Configuration
|
// # Other Configuration
|
||||||
//
|
//
|
||||||
// mapstructure is highly configurable. See the DecoderConfig struct
|
// mapstructure is highly configurable. See the DecoderConfig struct
|
||||||
// for other features and options that are supported.
|
// for other features and options that are supported.
|
||||||
|
|
|
@ -81,7 +81,6 @@ type PointerValueWalker interface {
|
||||||
//
|
//
|
||||||
// - Struct: skips all fields from being walked
|
// - Struct: skips all fields from being walked
|
||||||
// - StructField: skips walking the struct value
|
// - StructField: skips walking the struct value
|
||||||
//
|
|
||||||
var SkipEntry = errors.New("skip this entry")
|
var SkipEntry = errors.New("skip this entry")
|
||||||
|
|
||||||
// Walk takes an arbitrary value and an interface and traverses the
|
// Walk takes an arbitrary value and an interface and traverses the
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue