My requirement is to call the second API (Service B) as part of a single request to Service A from an authenticated user.
I am practicing go-swagger framework through a planned project. One of the point I am trying to implement is an authentic call from microservice-A to microservice-B. I have implemented without authentication but could not authenticate this internal-call.
I face an EOF
error on microservice-A side and service stops. I also see runtime error: index out of range [1] with length 1
error on microservice-B side.
Following is the code of ms-A (followed goswagger documentation) to communicate with ms-B:
transport := httptransport.New(apiclient.DefaultHost, apiclient.DefaultBasePath, apiclient.DefaultSchemes)
clientm := apiclient.New(transport, strfmt.Default)
bearerTokenAuth:= httptransport.BearerToken(os.Getenv("Authorization"))
resp, err := clientm.Show.Show(show.NewShowParams(),bearerTokenAuth)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", resp.Payload.Prompt)
The Show endpoint in microservice-B is simple entrypoint for testig this internal communication. I do have added security to the path in yaml file as following:
/show:
get:
description: "To test the entrypoint"
operationId: "show"
tags:
- "show"
security:
- Bearer: [ ]
responses:
200:
description: "Success response on hiting endpoint"
schema:
$ref: "#/definitions/Show"
400:
description: Bad Request
404:
description: items not found
500:
schema:
type: string
description: Server error
Errors
Microservice-A Error
//service-A which is used to hit show-endpoint of service-B
go run cmd/ustore-server/main.go --scheme http --port=8080
2021/10/08 01:47:00 Serving ustore at http://127.0.0.1:8080
2021/10/08 01:47:06 Get "http://localhost:9090/v1/show": EOF
exit status 1
Microservice-B Error
go run ./cmd/datastore-server/main.go --port=9090
2021/10/08 01:32:36 Serving datastore at http://127.0.0.1:9090
2021/10/08 01:34:14 http: panic serving 127.0.0.1:46040: runtime error: index out of range [1] with length 1
goroutine 23 [running]: