fx build fix
This commit is contained in:
51
api/server/internal/mutil/param/internal/helper.go
Normal file
51
api/server/internal/mutil/param/internal/helper.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package mutilimp
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func addParam(base string, param string) string {
|
||||
base = strings.TrimSuffix(base, "/")
|
||||
return fmt.Sprintf("%s/{%s}", base, param)
|
||||
}
|
||||
|
||||
func _ref(param string) string {
|
||||
return param + "_ref"
|
||||
}
|
||||
|
||||
func getParam(r *http.Request, paramName string) string {
|
||||
return chi.URLParam(r, paramName)
|
||||
}
|
||||
|
||||
type ParamHelper struct {
|
||||
t string
|
||||
}
|
||||
|
||||
func (ph *ParamHelper) Name() string {
|
||||
return ph.t
|
||||
}
|
||||
|
||||
func (ph *ParamHelper) RefName() string {
|
||||
return _ref(ph.Name())
|
||||
}
|
||||
|
||||
func (ph *ParamHelper) GetID(r *http.Request) string {
|
||||
return getParam(r, ph.RefName())
|
||||
}
|
||||
|
||||
func (ph *ParamHelper) GetRef(r *http.Request) (primitive.ObjectID, error) {
|
||||
return primitive.ObjectIDFromHex(ph.GetID(r))
|
||||
}
|
||||
|
||||
func (ph *ParamHelper) AddRef(base string) string {
|
||||
return addParam(base, ph.RefName())
|
||||
}
|
||||
|
||||
func CreateImp(resource string) *ParamHelper {
|
||||
return &ParamHelper{t: resource}
|
||||
}
|
||||
Reference in New Issue
Block a user