🚚 Renamed NewClientID to ParseClientID
This commit is contained in:
parent
2cc1fa02e7
commit
c31d47d5ae
|
@ -26,7 +26,7 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint: funlen
|
//nolint: funlen
|
||||||
func NewClientID(raw string) (*ClientID, error) {
|
func ParseClientID(raw string) (*ClientID, error) {
|
||||||
clientID := http.AcquireURI()
|
clientID := http.AcquireURI()
|
||||||
if err := clientID.Parse(nil, []byte(raw)); err != nil {
|
if err := clientID.Parse(nil, []byte(raw)); err != nil {
|
||||||
return nil, Error{
|
return nil, Error{
|
||||||
|
@ -113,7 +113,7 @@ func NewClientID(raw string) (*ClientID, error) {
|
||||||
func TestClientID(tb testing.TB) *ClientID {
|
func TestClientID(tb testing.TB) *ClientID {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
clientID, err := NewClientID("https://app.example.com/")
|
clientID, err := ParseClientID("https://app.example.com/")
|
||||||
require.NoError(tb, err)
|
require.NoError(tb, err)
|
||||||
|
|
||||||
return clientID
|
return clientID
|
||||||
|
@ -121,7 +121,7 @@ func TestClientID(tb testing.TB) *ClientID {
|
||||||
|
|
||||||
// UnmarshalForm implements a custom form.Unmarshaler.
|
// UnmarshalForm implements a custom form.Unmarshaler.
|
||||||
func (cid *ClientID) UnmarshalForm(v []byte) error {
|
func (cid *ClientID) UnmarshalForm(v []byte) error {
|
||||||
clientID, err := NewClientID(string(v))
|
clientID, err := ParseClientID(string(v))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("UnmarshalForm: %w", err)
|
return fmt.Errorf("UnmarshalForm: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ func (cid *ClientID) UnmarshalJSON(v []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
clientID, err := NewClientID(src)
|
clientID, err := ParseClientID(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("UnmarshalJSON: %w", err)
|
return fmt.Errorf("UnmarshalJSON: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint: funlen
|
//nolint: funlen
|
||||||
func TestNewClientID(t *testing.T) {
|
func TestParseClientID(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
for _, testCase := range []struct {
|
for _, testCase := range []struct {
|
||||||
|
@ -67,7 +67,7 @@ func TestNewClientID(t *testing.T) {
|
||||||
t.Run(testCase.name, func(t *testing.T) {
|
t.Run(testCase.name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
result, err := domain.NewClientID(testCase.input)
|
result, err := domain.ParseClientID(testCase.input)
|
||||||
if testCase.isValid {
|
if testCase.isValid {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, testCase.input, result.String())
|
assert.Equal(t, testCase.input, result.String())
|
||||||
|
|
|
@ -126,7 +126,7 @@ func NewSession(src *domain.Session) *Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Session) Populate(dst *domain.Session) {
|
func (t *Session) Populate(dst *domain.Session) {
|
||||||
dst.ClientID, _ = domain.NewClientID(t.ClientID)
|
dst.ClientID, _ = domain.ParseClientID(t.ClientID)
|
||||||
dst.Code = t.Code
|
dst.Code = t.Code
|
||||||
dst.CodeChallenge = t.CodeChallenge
|
dst.CodeChallenge = t.CodeChallenge
|
||||||
dst.CodeChallengeMethod, _ = domain.ParseCodeChallengeMethod(t.CodeChallengeMethod)
|
dst.CodeChallengeMethod, _ = domain.ParseCodeChallengeMethod(t.CodeChallengeMethod)
|
||||||
|
|
|
@ -90,7 +90,7 @@ func NewToken(src *domain.Token) *Token {
|
||||||
|
|
||||||
func (t *Token) Populate(dst *domain.Token) {
|
func (t *Token) Populate(dst *domain.Token) {
|
||||||
dst.AccessToken = t.AccessToken
|
dst.AccessToken = t.AccessToken
|
||||||
dst.ClientID, _ = domain.NewClientID(t.ClientID)
|
dst.ClientID, _ = domain.ParseClientID(t.ClientID)
|
||||||
dst.Me, _ = domain.NewMe(t.Me)
|
dst.Me, _ = domain.NewMe(t.Me)
|
||||||
dst.Scope = make(domain.Scopes, 0)
|
dst.Scope = make(domain.Scopes, 0)
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ func (useCase *tokenUseCase) Verify(ctx context.Context, accessToken string) (*d
|
||||||
result := &domain.Token{
|
result := &domain.Token{
|
||||||
AccessToken: accessToken,
|
AccessToken: accessToken,
|
||||||
}
|
}
|
||||||
result.ClientID, _ = domain.NewClientID(t.Issuer())
|
result.ClientID, _ = domain.ParseClientID(t.Issuer())
|
||||||
result.Me, _ = domain.NewMe(t.Subject())
|
result.Me, _ = domain.NewMe(t.Subject())
|
||||||
|
|
||||||
if scope, ok := t.Get("scope"); ok {
|
if scope, ok := t.Get("scope"); ok {
|
||||||
|
|
2
main.go
2
main.go
|
@ -102,7 +102,7 @@ func init() {
|
||||||
rootURL := config.Server.GetRootURL()
|
rootURL := config.Server.GetRootURL()
|
||||||
client.Name = []string{config.Name}
|
client.Name = []string{config.Name}
|
||||||
|
|
||||||
if client.ID, err = domain.NewClientID(rootURL); err != nil {
|
if client.ID, err = domain.ParseClientID(rootURL); err != nil {
|
||||||
logger.Fatalln("fail to read config:", err)
|
logger.Fatalln("fail to read config:", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue