added array to params
This commit is contained in:
+4
-4
@@ -27,7 +27,7 @@ func Init() API {
|
||||
mux.HandleFunc("/someapi", func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case "POST":
|
||||
h_SomeAPI(w, r)
|
||||
h_SomeAPI2(w, r)
|
||||
default:
|
||||
http.Error(w, "Method not allowed", 500)
|
||||
}
|
||||
@@ -35,12 +35,12 @@ func Init() API {
|
||||
return ret
|
||||
}
|
||||
|
||||
func h_SomeAPI(w http.ResponseWriter, r *http.Request) {
|
||||
func h_SomeAPI2(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
ctx := r.Context()
|
||||
ctx = context.WithValue(r.Context(), "REQ", r)
|
||||
ctx = context.WithValue(ctx, "RES", w)
|
||||
req := &ARequestStruct{}
|
||||
req := &AStr{}
|
||||
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||
err := json.NewDecoder(r.Body).Decode(&req)
|
||||
if err != nil {
|
||||
@@ -49,7 +49,7 @@ func h_SomeAPI(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
res, err := SomeAPI(ctx, req)
|
||||
res, err := SomeAPI2(ctx, req)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
|
||||
+26
-13
@@ -2,29 +2,42 @@ package goapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*@API*/
|
||||
type ARequestStruct struct {
|
||||
A *string `json:"a"`
|
||||
B int64
|
||||
C time.Time
|
||||
D *string
|
||||
}
|
||||
//
|
||||
///*@API*/
|
||||
//type ARequestStruct struct {
|
||||
// A *string `json:"a"`
|
||||
// B int64
|
||||
// C time.Time
|
||||
// D *string
|
||||
//}
|
||||
//
|
||||
///*@API*/
|
||||
//type AResponseStruct struct {
|
||||
// A string
|
||||
// B int64
|
||||
// C time.Time
|
||||
// D *string
|
||||
//}
|
||||
//
|
||||
///*
|
||||
//@API
|
||||
//@PATH: /someapi
|
||||
//*/
|
||||
//func SomeAPI(ctx context.Context, a *ARequestStruct) (*AResponseStruct, error) {
|
||||
// return nil, nil
|
||||
//}
|
||||
|
||||
/*@API*/
|
||||
type AResponseStruct struct {
|
||||
type AStr struct {
|
||||
A string
|
||||
B int64
|
||||
C time.Time
|
||||
D *string
|
||||
}
|
||||
|
||||
/*
|
||||
@API
|
||||
@PATH: /someapi
|
||||
*/
|
||||
func SomeAPI(ctx context.Context, a *ARequestStruct) (*AResponseStruct, error) {
|
||||
func SomeAPI2(ctx context.Context, a *AStr) ([]*AStr, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user