Skip to content

Commit

Permalink
Use "$" as prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Issei Horie committed Jan 15, 2019
1 parent 79fb37b commit 7a1347c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions notifier/typetalk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (
// EnvToken is Typetalk API Token
const EnvToken = "TYPETALK_TOKEN"

// EnvTopicID is Typetalk topic ID
const EnvTopicID = "TYPETALK_TOPIC_ID"

// Client represents Typetalk API client.
type Client struct {
*typetalk.Client
Expand All @@ -38,21 +41,25 @@ type service struct {

// NewClient returns Client initialized with Config
func NewClient(cfg Config) (*Client, error) {
token := cfg.Token
token := os.ExpandEnv(cfg.Token)
if token == EnvToken {
token = os.Getenv(EnvToken)
}
if token == "" {
return &Client{}, errors.New("Typetalk token is missing")
}

if cfg.TopicID == "" {
topicIDString := os.ExpandEnv(cfg.TopicID)
if topicIDString == EnvTopicID {
topicIDString = os.Getenv(EnvTopicID)
}
if topicIDString == "" {
return &Client{}, errors.New("Typetalk topic ID is missing")
}

topicID, err := strconv.Atoi(cfg.TopicID)
topicID, err := strconv.Atoi(topicIDString)
if err != nil {
return &Client{}, err
return &Client{}, errors.New("Typetalk topic ID is not numeric value")
}

client := typetalk.NewClient(nil)
Expand Down

0 comments on commit 7a1347c

Please sign in to comment.