28 lines
459 B
Go
28 lines
459 B
Go
package request
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"fmt"
|
|
)
|
|
|
|
type Authorization interface {
|
|
Token() string
|
|
}
|
|
|
|
type BasicAuth struct {
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
type BearerAuth struct {
|
|
AccessToken string
|
|
}
|
|
|
|
func (auth *BasicAuth) Token() string {
|
|
return fmt.Sprintf("Basic %s", base64.StdEncoding.EncodeToString([]byte(auth.Username+":"+auth.Password)))
|
|
}
|
|
|
|
func (auth *BearerAuth) Token() string {
|
|
return fmt.Sprintf("Bearer %s", auth.AccessToken)
|
|
}
|