This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package app | |
import ( | |
// imports go here | |
"github.com/spf13/viper" | |
) | |
// Common errors returned by this app. | |
var ( | |
ErrShutdown = fmt.Errorf("application shutdown gracefully") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/madflojo/go-quick/app" | |
"github.com/sirupsen/logrus" | |
"github.com/spf13/viper" | |
) | |
func main() { | |
// Initiate a simple logger |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load Config | |
cfg.AddConfigPath("./conf") | |
cfg.SetEnvPrefix("app") | |
cfg.AllowEmptyEnv(true) | |
cfg.AutomaticEnv() | |
err := cfg.ReadInConfig() | |
if err != nil { | |
switch err.(type) { | |
case viper.ConfigFileNotFoundError: | |
log.Warnf("No Config file found, loaded config from Environment - Default path ./conf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go-quick: | |
config: '{"from_consul": true, "debug": false, "trace": false}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load Config | |
cfg.AddConfigPath("./conf") | |
cfg.SetEnvPrefix("app") | |
cfg.AllowEmptyEnv(true) | |
cfg.AutomaticEnv() | |
err := cfg.ReadInConfig() | |
if err != nil { | |
switch err.(type) { | |
case viper.ConfigFileNotFoundError: | |
log.Warnf("No Config file found, loaded config from Environment - Default path ./conf") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/madflojo/go-quick/app" | |
"github.com/sirupsen/logrus" | |
"github.com/spf13/viper" | |
// Add remote provider support to Viper | |
_ "github.com/spf13/viper/remote" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setup Scheduler | |
scheduler = tasks.New() | |
defer scheduler.Stop() | |
// Config Reload | |
if cfg.GetInt("config_watch_interval") > 0 { | |
_, err := scheduler.Add(&tasks.Task{ | |
Interval: time.Duration(cfg.GetInt("config_watch_interval")) * time.Second, | |
TaskFunc: func() error { | |
// Reload config using Viper's Watch capabilities |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
) | |
// handler is a basic HTTP handler that prints hello world. | |
func handler(w http.ResponseWriter, r *http.Request) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/julienschmidt/httprouter" | |
"log" | |
"net/http" | |
) | |
// handler is a basic HTTP handler that prints hello world. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// handler is a basic HTTP handler that prints hello world. | |
func handler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) { | |
fmt.Fprintf(w, "Hello %s", ps.ByName("name")) | |
} |