File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,16 +14,13 @@ type Response struct {
1414
1515func main () {
1616 var response Response
17- end := httpclient.Endpoint {
17+ endpoint := httpclient.JSONEndpoint [ Response ] {
1818 URL : "https://api.ipify.org?format=json" ,
1919 Route : "" ,
2020 Method : http .MethodGet ,
2121 Authorization : "" ,
2222 Data : nil ,
23- }
24- endpoint := httpclient.JSONEndpoint [Response ]{
25- Endpoint : end ,
26- Response : response ,
23+ Response : response ,
2724 }
2825 answer , err := endpoint .GetJSON (response )
2926 if err != nil {
Original file line number Diff line number Diff line change @@ -19,9 +19,13 @@ type Endpoint struct {
1919 Data any
2020}
2121
22- type JSONEndpoint [T comparable ] struct {
23- Endpoint
24- Response T
22+ type JSONEndpoint [T any ] struct {
23+ URL string
24+ Method string
25+ Route string
26+ Authorization string
27+ Data any
28+ Response T
2529}
2630
2731func init () {
Original file line number Diff line number Diff line change @@ -96,17 +96,14 @@ func TestGetJSON(t *testing.T) {
9696 response := struct {
9797 JWT string
9898 }{}
99- e := Endpoint {
100- URL : "http://firefly.nusak.ca" ,
101- Route : "/login" ,
102- Method : http .MethodPost ,
103- Data : data ,
99+ e := JSONEndpoint [struct { JWT string }]{
100+ URL : "http://firefly.nusak.ca" ,
101+ Route : "/login" ,
102+ Method : http .MethodPost ,
103+ Data : data ,
104+ Response : response ,
104105 }
105- g := JSONEndpoint [struct { JWT string }]{
106- e ,
107- response ,
108- }
109- answer , err := g .GetJSON (response )
106+ answer , err := e .GetJSON (response )
110107 is .NoErr (err )
111108 answerType := fmt .Sprintf ("%T" , answer )
112109 is .True (answerType == "struct { JWT string }" )
You can’t perform that action at this time.
0 commit comments