Skip to content

Commit

Permalink
bump timeout and allow configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ripexz committed May 8, 2019
1 parent 978ddfa commit 6b17e0b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Config struct {
BaseURL string
Silent bool
Debug bool
Timeout int64
}

func loadEnv(config *Config) {
Expand All @@ -23,11 +24,15 @@ func loadEnv(config *Config) {
if v, e := strconv.ParseBool(os.Getenv("LOGPASTA_DEBUG")); e == nil {
config.Debug = v
}
if v, e := strconv.ParseInt(os.Getenv("LOGPASTA_TIMEOUT"), 10, 64); e == nil {
config.Timeout = v
}
}

func loadFlags(config *Config) {
flag.StringVar(&config.BaseURL, "u", config.BaseURL, "logpasta base url, without trailing slash")
flag.BoolVar(&config.Silent, "s", config.Silent, "silent mode - suppress logs unless request fails")
flag.BoolVar(&config.Debug, "d", config.Debug, "debug mode - output debug information")
flag.Int64Var(&config.Timeout, "t", config.Timeout, "timeout - http client timeout in seconds")
flag.Parse()
}
8 changes: 5 additions & 3 deletions logpasta.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

var (
baseURL = "https://www.logpasta.com"
version = "v0.1.0"
version = "v0.1.1"
)

func main() {
Expand All @@ -31,15 +31,17 @@ func main() {
conf := Config{
BaseURL: baseURL,
Silent: true,
Timeout: 5,
}
loadEnv(&conf)
loadFlags(&conf)

if conf.Debug {
log.Printf("Running with config:\n - BaseURL: %s\n - Silent: %v\n - Debug: %v",
log.Printf("Running with config:\n - BaseURL: %s\n - Silent: %v\n - Debug: %v\n - Timeout: %d",
conf.BaseURL,
conf.Silent,
conf.Debug,
conf.Timeout,
)
}

Expand Down Expand Up @@ -71,7 +73,7 @@ func main() {
}

func saveLog(conf *Config, content string) (string, error) {
client := http.Client{Timeout: time.Second}
client := http.Client{Timeout: time.Second * time.Duration(conf.Timeout)}

data := &PasteData{
Paste: Paste{
Expand Down

0 comments on commit 6b17e0b

Please sign in to comment.