MCPcopy Index your code
hub / github.com/yusing/godoxy / executeEndpoint

Function executeEndpoint

cmd/cli/cli.go:122–190  ·  view source on GitHub ↗
(addrFlag string, ep Endpoint, args []string)

Source from the content-addressed store, hash-verified

120}
121
122func executeEndpoint(addrFlag string, ep Endpoint, args []string) error {
123 fs := flag.NewFlagSet(strings.Join(ep.CommandPath, "-"), flag.ContinueOnError)
124 fs.SetOutput(io.Discard)
125 useWS := false
126 if ep.IsWebSocket {
127 fs.BoolVar(&useWS, "ws", false, "use websocket")
128 }
129 typedValues := make(map[string]any, len(ep.Params))
130 isSet := make(map[string]bool, len(ep.Params))
131 for _, p := range ep.Params {
132 switch p.Type {
133 case "integer":
134 v := new(int)
135 fs.IntVar(v, p.FlagName, 0, p.Description)
136 typedValues[p.FlagName] = v
137 case "number":
138 v := new(float64)
139 fs.Float64Var(v, p.FlagName, 0, p.Description)
140 typedValues[p.FlagName] = v
141 case "boolean":
142 v := new(bool)
143 fs.BoolVar(v, p.FlagName, false, p.Description)
144 typedValues[p.FlagName] = v
145 case "array":
146 v := &stringSliceFlag{}
147 fs.Var(v, p.FlagName, p.Description+" (comma-separated)")
148 typedValues[p.FlagName] = v
149 default:
150 v := new(string)
151 fs.StringVar(v, p.FlagName, "", p.Description)
152 typedValues[p.FlagName] = v
153 }
154 }
155 if err := fs.Parse(args); err != nil {
156 return fmt.Errorf("%w\n\n%s", err, formatEndpointHelp(ep))
157 }
158 if len(fs.Args()) > 0 {
159 return fmt.Errorf("unexpected args: %s\n\n%s", strings.Join(fs.Args(), " "), formatEndpointHelp(ep))
160 }
161 fs.Visit(func(f *flag.Flag) {
162 isSet[f.Name] = true
163 })
164
165 for _, p := range ep.Params {
166 if !p.Required {
167 continue
168 }
169 if !isSet[p.FlagName] {
170 return fmt.Errorf("missing required flag --%s\n\n%s", p.FlagName, formatEndpointHelp(ep))
171 }
172 }
173
174 baseURL, err := resolveBaseURL(addrFlag)
175 if err != nil {
176 return err
177 }
178 reqURL, body, err := buildRequest(ep, baseURL, typedValues, isSet)
179 if err != nil {

Callers 1

runFunction · 0.85

Calls 7

formatEndpointHelpFunction · 0.85
resolveBaseURLFunction · 0.85
buildRequestFunction · 0.85
execWebsocketFunction · 0.85
execHTTPFunction · 0.85
NewMethod · 0.80
ParseMethod · 0.45

Tested by

no test coverage detected