Skip to content

Commit f223ed5

Browse files
committed
Changed to get the domain from url.
1 parent b9d4334 commit f223ed5

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

tokenOp.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,31 @@ package networkutil
22

33
import (
44
"net/http"
5+
"net/url"
6+
"strings"
57
)
68

79
type TokenOperation struct {
810
CookieOp CookieOperation
911
}
1012

11-
func NewTokenOp(domain string) *TokenOperation {
13+
// Create tokenOp.
14+
//
15+
// Arguments;
16+
// apiUrl {string} - URL of the API you are using.
17+
func NewTokenOp(apiUrl string) (*TokenOperation, error) {
18+
u, err := url.Parse(apiUrl)
19+
if err != nil {
20+
return nil, err
21+
}
22+
splittedHost := strings.Split(u.String(), ".")
23+
hostLen := len(splittedHost)
24+
domain := strings.Join(splittedHost[hostLen-2:], ".")
25+
1226
cookieOp := NewCookieOp(domain)
1327
return &TokenOperation{
1428
CookieOp: *cookieOp,
15-
}
29+
}, nil
1630
}
1731

1832
// Set the refresh token.

0 commit comments

Comments
 (0)