Skip to content

Commit

Permalink
adjust interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Songmu committed Jul 7, 2019
1 parent 56854ac commit cf522ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
12 changes: 2 additions & 10 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"strings"

"golang.org/x/xerrors"
Expand Down Expand Up @@ -35,15 +34,8 @@ type budget struct {
Remaining int `json:"remaining,string"`
}

func New(ver string) (*Client, error) {
cli := &Client{token: os.Getenv("KIBELA_TOKEN")}
if cli.token == "" {
return nil, fmt.Errorf("set token by KIBELA_TOKEN env value")
}
team := os.Getenv("KIBELA_TEAM")
if team == "" {
return nil, fmt.Errorf("set team name by KIBELA_TEAM env value")
}
func New(ver, team, token string) (*Client, error) {
cli := &Client{token: token}
cli.endpoint = fmt.Sprintf(endpointBase, team)
cli.limiter = newRateLimitRoundTripper()
cli.cli = &http.Client{Transport: cli.limiter}
Expand Down
20 changes: 17 additions & 3 deletions kibela/kibela.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ import (
"golang.org/x/xerrors"
)

const (
envKibelaDIR = "KIBELA_DIR"
envKibelaTEAM = "KIBELA_TEAM"
envKibelaTOKEN = "KIBELA_TOKEN"
)

var defaultDir = "notes"

func init() {
d := os.Getenv("KIBELA_DIR")
d := os.Getenv(envKibelaDIR)
if d != "" {
defaultDir = d
}
Expand All @@ -29,13 +35,21 @@ type Kibela struct {
}

func New(ver string) (*Kibela, error) {
cli, err := client.New(ver)
token := os.Getenv(envKibelaTOKEN)
if token == "" {
return nil, fmt.Errorf("set token by KIBELA_TOKEN env value")
}
team := os.Getenv(envKibelaTEAM)
if team == "" {
return nil, fmt.Errorf("set team name by KIBELA_TEAM env value")
}
cli, err := client.New(ver, team, token)
if err != nil {
return nil, xerrors.Errorf("failed to kibela.New: %w", err)
}
return &Kibela{
cli: cli,
team: os.Getenv("KIBELA_TEAM"),
team: team,
}, nil
}

Expand Down

0 comments on commit cf522ad

Please sign in to comment.