package services import ( "context" "fmt" "git.dynamicdiscord.de/malobeo/portal/internal" "git.dynamicdiscord.de/malobeo/portal/openapi" "os" ) var ( Users UserService = UserService{} ) type UserService struct{} // return jwt tokenstring on success func (u *UserService) Login(username string, password string) (*openapi.Token, error) { //grantType := "grantType_example" // string | (optional) //scope := "scope_example" // string | (optional) (default to "") //clientId := "clientId_example" // string | (optional) //clientSecret := "clientSecret_example" // string | (optional) fmt.Fprintf(os.Stdout, "Try login with username: %s, password: %s", username, password) apiClient := internal.GetApiClient() resp, r, err := apiClient.TokenAPI.LoginForAccessTokenTokenPost(context.Background()).Username(username).Password(password).Execute() //configuration := openapi.NewConfiguration() //configuration.Host = "localhost:8000" //configuration.Scheme = "http" //apiClient := openapi.NewAPIClient(configuration) //resp, r, err := apiClient.TokenAPI.LoginForAccessTokenTokenPost(context.Background()).Username(username).Password(password).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error when calling `TokenAPI.LoginForAccessTokenTokenPost``: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) return nil, err } // response from `LoginForAccessTokenTokenPost`: Token fmt.Fprintf(os.Stdout, "Response from `TokenAPI.LoginForAccessTokenTokenPost`: %v\n", resp) return resp, nil }