package data import "f1-game/internal/code" type ( protoRouteRow struct { Enable bool `json:"enable"` Name string `json:"name"` Route string `json:"route"` Request string `json:"request"` Response string `json:"response"` Push string `json:"push"` Notify string `json:"notify"` Desc string `json:"desc"` AllowRequest bool `json:"-"` } protoRouteConfig struct { maps map[string]*protoRouteRow } ) func (p *protoRouteConfig) Name() string { return "proto_route" } func (p *protoRouteConfig) Init() { p.maps = map[string]*protoRouteRow{} } func (p *protoRouteConfig) OnLoad(maps any, _ bool) (int, error) { var list []*protoRouteRow if err := DecodeData(maps, &list); err != nil { return 0, err } loadMaps := map[string]*protoRouteRow{} for _, row := range list { loadMaps[row.Route] = row if row.Request != "" || row.Notify != "" { row.AllowRequest = true continue } } p.maps = loadMaps return len(list), nil } func (p *protoRouteConfig) OnAfterLoad(_ bool) { } func (p *protoRouteConfig) Contain(route string) int32 { row, found := p.maps[route] if !found { return code.RouteNotFound } if !row.Enable { return code.RouteIsDisabled } if !row.AllowRequest { return code.RouteTypeError } return code.OK }