From c31d47d5aeac2fa53f509d0de8429c400b537be1 Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Sat, 29 Jan 2022 19:45:49 +0500 Subject: [PATCH] :truck: Renamed NewClientID to ParseClientID --- internal/domain/client_id.go | 8 ++++---- internal/domain/client_id_test.go | 4 ++-- internal/session/repository/sqlite3/sqlite3_session.go | 2 +- internal/token/repository/sqlite3/sqlite3_token.go | 2 +- internal/token/usecase/token_ucase.go | 2 +- main.go | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/domain/client_id.go b/internal/domain/client_id.go index 993941f..fa5eb5a 100644 --- a/internal/domain/client_id.go +++ b/internal/domain/client_id.go @@ -26,7 +26,7 @@ var ( ) //nolint: funlen -func NewClientID(raw string) (*ClientID, error) { +func ParseClientID(raw string) (*ClientID, error) { clientID := http.AcquireURI() if err := clientID.Parse(nil, []byte(raw)); err != nil { return nil, Error{ @@ -113,7 +113,7 @@ func NewClientID(raw string) (*ClientID, error) { func TestClientID(tb testing.TB) *ClientID { tb.Helper() - clientID, err := NewClientID("https://app.example.com/") + clientID, err := ParseClientID("https://app.example.com/") require.NoError(tb, err) return clientID @@ -121,7 +121,7 @@ func TestClientID(tb testing.TB) *ClientID { // UnmarshalForm implements a custom form.Unmarshaler. func (cid *ClientID) UnmarshalForm(v []byte) error { - clientID, err := NewClientID(string(v)) + clientID, err := ParseClientID(string(v)) if err != nil { return fmt.Errorf("UnmarshalForm: %w", err) } @@ -137,7 +137,7 @@ func (cid *ClientID) UnmarshalJSON(v []byte) error { return err } - clientID, err := NewClientID(src) + clientID, err := ParseClientID(src) if err != nil { return fmt.Errorf("UnmarshalJSON: %w", err) } diff --git a/internal/domain/client_id_test.go b/internal/domain/client_id_test.go index 08c85eb..7fe9e33 100644 --- a/internal/domain/client_id_test.go +++ b/internal/domain/client_id_test.go @@ -10,7 +10,7 @@ import ( ) //nolint: funlen -func TestNewClientID(t *testing.T) { +func TestParseClientID(t *testing.T) { t.Parallel() for _, testCase := range []struct { @@ -67,7 +67,7 @@ func TestNewClientID(t *testing.T) { t.Run(testCase.name, func(t *testing.T) { t.Parallel() - result, err := domain.NewClientID(testCase.input) + result, err := domain.ParseClientID(testCase.input) if testCase.isValid { require.NoError(t, err) assert.Equal(t, testCase.input, result.String()) diff --git a/internal/session/repository/sqlite3/sqlite3_session.go b/internal/session/repository/sqlite3/sqlite3_session.go index a7e1690..cc91ac0 100644 --- a/internal/session/repository/sqlite3/sqlite3_session.go +++ b/internal/session/repository/sqlite3/sqlite3_session.go @@ -126,7 +126,7 @@ func NewSession(src *domain.Session) *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.CodeChallenge = t.CodeChallenge dst.CodeChallengeMethod, _ = domain.ParseCodeChallengeMethod(t.CodeChallengeMethod) diff --git a/internal/token/repository/sqlite3/sqlite3_token.go b/internal/token/repository/sqlite3/sqlite3_token.go index fb0629e..83c8fc3 100644 --- a/internal/token/repository/sqlite3/sqlite3_token.go +++ b/internal/token/repository/sqlite3/sqlite3_token.go @@ -90,7 +90,7 @@ func NewToken(src *domain.Token) *Token { func (t *Token) Populate(dst *domain.Token) { dst.AccessToken = t.AccessToken - dst.ClientID, _ = domain.NewClientID(t.ClientID) + dst.ClientID, _ = domain.ParseClientID(t.ClientID) dst.Me, _ = domain.NewMe(t.Me) dst.Scope = make(domain.Scopes, 0) diff --git a/internal/token/usecase/token_ucase.go b/internal/token/usecase/token_ucase.go index bb8dbce..1e2329d 100644 --- a/internal/token/usecase/token_ucase.go +++ b/internal/token/usecase/token_ucase.go @@ -106,7 +106,7 @@ func (useCase *tokenUseCase) Verify(ctx context.Context, accessToken string) (*d result := &domain.Token{ AccessToken: accessToken, } - result.ClientID, _ = domain.NewClientID(t.Issuer()) + result.ClientID, _ = domain.ParseClientID(t.Issuer()) result.Me, _ = domain.NewMe(t.Subject()) if scope, ok := t.Get("scope"); ok { diff --git a/main.go b/main.go index e6e382d..56398a9 100644 --- a/main.go +++ b/main.go @@ -102,7 +102,7 @@ func init() { rootURL := config.Server.GetRootURL() 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) }