package main
import (
"context"
"net/http"
"github.com/horizon-games/go-skyweaver/proto"
)
var DefaultHTTPClient = &http.Client{}
func newAPIClient(baseURL string) (proto.SkyWeaverAPI, error) {
client := proto.NewSkyWeaverAPIClient(baseURL, DefaultHTTPClient)
return client, nil
}
func authHeaderContext(jwtToken string, ctx context.Context) context.Context {
headers := http.Header{}
headers.Set("Authorization", fmt.Sprintf("BEARER %s", jwtToken))
ctx, err := proto.WithHTTPRequestHeaders(ctx, headers)
if err != nil {
panic(err.Error())
}
return ctx
}
func main(){
ctx := context.Background()
ctx = authHeaderContext("jwt_token", ctx)
client, err := newAPIClient("base url")
resp, err := client.Ping(ctx)
}