Skip to content

Commit

Permalink
Changed to get the domain from url.
Browse files Browse the repository at this point in the history
  • Loading branch information
cateiru committed Aug 28, 2021
1 parent b9d4334 commit f223ed5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions tokenOp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,31 @@ package networkutil

import (
"net/http"
"net/url"
"strings"
)

type TokenOperation struct {
CookieOp CookieOperation
}

func NewTokenOp(domain string) *TokenOperation {
// Create tokenOp.
//
// Arguments;
// apiUrl {string} - URL of the API you are using.
func NewTokenOp(apiUrl string) (*TokenOperation, error) {
u, err := url.Parse(apiUrl)
if err != nil {
return nil, err
}
splittedHost := strings.Split(u.String(), ".")
hostLen := len(splittedHost)
domain := strings.Join(splittedHost[hostLen-2:], ".")

cookieOp := NewCookieOp(domain)
return &TokenOperation{
CookieOp: *cookieOp,
}
}, nil
}

// Set the refresh token.
Expand Down

0 comments on commit f223ed5

Please sign in to comment.