updated functions names

This commit is contained in:
Paul 2023-12-24 09:36:33 +01:00
parent d03dc8b6cd
commit 137cbd8d01
4 changed files with 24 additions and 24 deletions

View File

@ -12,7 +12,7 @@ import (
const ipv4_cidr_regex = `^(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|)){4}\/([1-3])?([0-9])?$)`
func GetTrustlists(cfg config.Config) (res []string, err error) {
func GetTrustlists(cfg *config.Config) (res []string, err error) {
var ctl []CfgTrustlist
err = cfg.Db.Find(&ctl)
@ -24,7 +24,7 @@ func GetTrustlists(cfg config.Config) (res []string, err error) {
return
}
func (tl CfgTrustlist) InsertOrUpdate(cfg config.Config) (err error) {
func (tl CfgTrustlist) InsertOrUpdate(cfg *config.Config) (err error) {
var w = Cfg{Key: "trustlist"}
exists, _ := cfg.Db.Get(&w)
@ -42,7 +42,7 @@ func (tl CfgTrustlist) InsertOrUpdate(cfg config.Config) (err error) {
return fmt.Errorf("no trustlist updated")
}
func (tl CfgTrustlist) Delete(cfg config.Config, ip string) (affected int64, err error) {
func (tl CfgTrustlist) Delete(cfg *config.Config, ip string) (affected int64, err error) {
var w = CfgTrustlist{IP: ip}
exists, _ := cfg.Db.Get(&w)
@ -58,7 +58,7 @@ func (tl CfgTrustlist) Verify() bool {
return reg.MatchString(tl.IP)
}
func (cfgset *CfgSet) BuildRegex(cfg config.Config) {
func (cfgset *CfgSet) BuildRegex(cfg *config.Config) {
var rr []CfgExpr
err := cfg.Db.Where("cfgset_id = $1 AND enabled", cfgset.ID).OrderBy("expr").Find(&rr)
if err != nil {
@ -71,7 +71,7 @@ func (cfgset *CfgSet) BuildRegex(cfg config.Config) {
cfgset.Regex = fmt.Sprintf("(%s)", strings.Join(regs, "|"))
}
func GetSets(cfg config.Config) (res []CfgSet, err error) {
func GetSets(cfg *config.Config) (res []CfgSet, err error) {
var w = []CfgSet{}
if err := cfg.Db.Where("enabled").Find(&w); err == nil {
@ -80,7 +80,7 @@ func GetSets(cfg config.Config) (res []CfgSet, err error) {
return
}
func GetGlobalConfig(cfg config.Config) (res []Cfg, err error) {
func GetGlobalConfig(cfg *config.Config) (res []Cfg, err error) {
var w = []Cfg{}
if err := cfg.Db.Find(&w); err == nil {
@ -89,7 +89,7 @@ func GetGlobalConfig(cfg config.Config) (res []Cfg, err error) {
return
}
func GetAllConfigv2(cfg config.Config) (res CfgAllv2, err error) {
func GetAllConfigv2(cfg *config.Config) (res CfgAllv2, err error) {
var c = make(map[string]string)
var tmpcfg = []Cfg{}
if err := cfg.Db.Find(&tmpcfg); err == nil {
@ -123,7 +123,7 @@ func GetAllConfigv2(cfg config.Config) (res CfgAllv2, err error) {
return
}
func InsertOrUpdateSets(cfg config.Config, folders []CfgSet) (res string, err error) {
func InsertOrUpdateSets(cfg *config.Config, folders []CfgSet) (res string, err error) {
var w = Cfg{Key: "folders"}
if exists, _ := cfg.Db.Get(&w); exists {
@ -140,7 +140,7 @@ func InsertOrUpdateSets(cfg config.Config, folders []CfgSet) (res string, err er
return
}
func GetWS(cfg config.Config) (res []CfgWS, err error) {
func GetWS(cfg *config.Config) (res []CfgWS, err error) {
var w = []CfgWS{}
if err = cfg.Db.Find(&w); err == nil {
@ -149,7 +149,7 @@ func GetWS(cfg config.Config) (res []CfgWS, err error) {
return
}
func DiscoverURLS(cfg config.Config, routes []*echo.Route) (Discovery, error) {
func DiscoverURLS(cfg *config.Config, routes []*echo.Route) (Discovery, error) {
var disc Discovery
var urls = make(map[string]Url)
for _, j := range routes {

View File

@ -118,21 +118,21 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
})
e.GET("/config", func(c echo.Context) (err error) {
if c.QueryParam("v") == "2" {
globalconfig, err := models.GetAllConfigv2(*cfg)
globalconfig, err := models.GetAllConfigv2(cfg)
return Result(c, err, globalconfig)
}
globalconfig, err := models.GetGlobalConfig(*cfg)
globalconfig, err := models.GetGlobalConfig(cfg)
return Result(c, err, globalconfig)
})
e.GET("/config/trustlist", func(c echo.Context) (err error) {
trustlists, err := models.GetTrustlists(*cfg)
trustlists, err := models.GetTrustlists(cfg)
return Result(c, err, trustlists)
})
e.POST("/config/trustlist", func(c echo.Context) (err error) {
var cidr models.CfgTrustlist
err = c.Bind(&cidr)
if err == nil && cidr.Verify() {
err = cidr.InsertOrUpdate(*cfg)
err = cidr.InsertOrUpdate(cfg)
return Result(c, err, cidr)
}
return Result(c, err, nil)
@ -140,28 +140,28 @@ func RegisterRoutes(e *echo.Echo, ctx *context.Context, cfg *config.Config) {
e.DELETE("/config/trustlist/:ip", func(c echo.Context) (err error) {
var ip = c.Param("ip")
var cidr models.CfgTrustlist
_, err = cidr.Delete(*cfg, ip)
_, err = cidr.Delete(cfg, ip)
return
})
e.GET("/config/sets", func(c echo.Context) (err error) {
sets, err := models.GetSets(*cfg)
sets, err := models.GetSets(cfg)
return Result(c, err, sets)
})
e.GET("/config/ws", func(c echo.Context) (err error) {
folders, err := models.GetWS(*cfg)
folders, err := models.GetWS(cfg)
return Result(c, err, folders)
})
e.GET("/discovery", func(c echo.Context) (err error) {
disc, err := models.DiscoverURLS(*cfg, e.Routes())
disc, err := models.DiscoverURLS(cfg, e.Routes())
return Result(c, err, disc)
})
e.File("/test.html", "/home/paul/test.html")
e.GET("/wsps", func(c echo.Context) (err error) {
ws.HandleWSPS(c, cfg)
ws.HandleWSPS(&c, cfg)
return
})
e.GET("/wsrr", func(c echo.Context) (err error) {
ws.HandleWSRR(c, cfg)
ws.HandleWSRR(&c, cfg)
return
})
}

View File

@ -11,7 +11,7 @@ import (
)
// HandleWSPS handle pub sub flows
func HandleWSPS(c echo.Context, cfg *config.Config) (err error) {
func HandleWSPS(c *echo.Context, cfg *config.Config) (err error) {
websocket.Handler(func(ws *websocket.Conn) {
defer ws.Close()
@ -38,6 +38,6 @@ func HandleWSPS(c echo.Context, cfg *config.Config) (err error) {
for {
time.Sleep(50 * time.Millisecond)
}
}).ServeHTTP(c.Response(), c.Request())
}).ServeHTTP((*c).Response(), (*c).Request())
return nil
}

View File

@ -11,7 +11,7 @@ import (
)
// HandleWSRR handle req rep flows
func HandleWSRR(c echo.Context, cfg *config.Config) error {
func HandleWSRR(c *echo.Context, cfg *config.Config) error {
websocket.Handler(func(ws *websocket.Conn) {
defer ws.Close()
@ -99,6 +99,6 @@ func HandleWSRR(c echo.Context, cfg *config.Config) error {
log.Println(err)
}
}
}).ServeHTTP(c.Response(), c.Request())
}).ServeHTTP((*c).Response(), (*c).Request())
return nil
}