Exemple #1
0
func main() {
	logger := log.NewLog(
		log.WithLevel(log.InfoLevel),
		log.WithFields(log.Fields{
			"logger": "os",
		}),
		log.WithOutput(
			log.NewOutput(log.OutputName("/dev/stdout")),
		),
	)

	for i := 0; i < 100; i++ {
		logger.Info("This is a log message")
		time.Sleep(time.Second)
	}
}
Exemple #2
0
type Option func(o *Options)

type router struct {
	opts Options

	// TODO: optimise for concurrency
	sync.RWMutex
	routes Routes
}

var (
	// Default config source file
	DefaultFile   = "routes.json"
	DefaultPath   = []string{"api"}
	DefaultLogger = log.NewLog(log.WithOutput(log.NewOutput(log.OutputName("/dev/stderr"))))
)

func (r *router) update(routes Routes) {
	// sort routes
	sort.Sort(sortedRoutes{routes})
	// update
	r.Lock()
	r.routes = routes
	r.Unlock()
}

func (r *router) run(c config.Config) {
	var routes Routes

	// load routes immediately if possible