Пример #1
0
func main() {
	env.Parse("RS", false)

	router := mux.NewRouter()
	router.HandleFunc("/", PrintDoc).Methods("GET")
	router.HandleFunc("/{node}/{oid}", GetOID).Methods("GET")
	n := negroni.New(
		negroni.NewRecovery(),
		logger.NewLogger(),
	)
	n.UseHandler(router)

	http.ListenAndServe(config.Listen+":"+config.Port, n)
}
Пример #2
0
func main() {
	env.Parse("NETMGMT", false)

	duration, err := strconv.Atoi(config.LockDuration)
	if err != nil {
		log.Fatal(err)
	}

	locker.Init(duration)

	f, err := os.Open(config.File)
	defer f.Close()
	if err != nil {
		log.Fatal(err)
	}

	b, err := ioutil.ReadAll(f)
	if err != nil {
		log.Fatal(err)
	}

	networks, err = ReadNetworks(b)
	if err != nil {
		log.Fatal(err)
	}

	router := mux.NewRouter()
	router.HandleFunc("/nodes/{node}", GetNodeInfo).Methods("GET")
	router.HandleFunc("/networks", GetNetworks).Methods("GET")
	router.HandleFunc("/networks/{net}", GetNetwork).Methods("GET")
	router.HandleFunc("/networks/{net}/ips", GetNetworkIps).Methods("GET")
	router.HandleFunc("/networks/{net}", PostReservation).Methods("POST")
	router.HandleFunc("/conf", GetConfig).Methods("GET")
	router.HandleFunc("/ui", GetUI).Methods("GET")

	n := negroni.New(
		negroni.NewRecovery(),
		logger.NewLogger(),
		cors.New(cors.Options{AllowedOrigins: []string{"*"}}),
	)
	n.UseHandler(router)

	http.ListenAndServe(config.Address+":"+config.Port, n)

}
Пример #3
0
func main() {
	env.Parse("GERTY", false)

	s, err := store.New("sqlitestore", cfg.Store)
	if err != nil {
		panic(err)
	}

	ri := entities.NewRoleInteractor(s.Roles)
	ni := entities.NewNodeInteractor(s.Nodes, ri)

	r := mux.NewRouter().StrictSlash(true)

	err = api.Configure(cfg)
	if err != nil {
		panic(err)
	}
	api.Inject(ni, ri)
	a := r.PathPrefix("/api/").Subrouter()
	api.PopulateRouter(a)

	transformers.Inject(ni, ri)
	t := r.PathPrefix("/transformers/").Subrouter()
	transformers.PopulateRouter(t)

	wh := mw.WebHook{
		FileName: cfg.JenkinsFileName,
		Token:    cfg.JenkinsToken,
		JobName:  cfg.JenkinsJobName,
		BaseUrl:  cfg.JenkinsBaseUrl,
	}

	chain := alice.New(
		mw.RecoverPanic,
		mw.CorsHeaders,
		mw.UserContext,
		wh.Create,
	).Then(r)

	log.Fatal(http.ListenAndServe(cfg.Address+":"+cfg.Port, chain))
}