Ejemplo n.º 1
0
func (app *App) init(cfg config.Config) {
	dbCfg := cfg.GetSection("database")
	host := dbCfg.GetStr("host")
	port := dbCfg.GetInt16("port")
	user := dbCfg.GetStr("username")
	pass := dbCfg.GetStr("password")
	dbname := dbCfg.GetStr("dbname")
	log.Printf("connect mysql: host=%s, port=%d, user=%s, pass=%s, dbname=%s",
		host, port, user, pass, dbname)
	db.Open(host, port, user, pass, dbname)
}
Ejemplo n.º 2
0
func main() {
	var port int
	var disableAuth bool

	flag.IntVar(&port, "port", 8081, "Port the server listens to")
	flag.BoolVar(&disableAuth, "disableAuth", false, "Disables authentication requirements")

	flag.Parse()

	db.Open()
	defer db.Db.Close()
	server.Run(port, disableAuth)
}
Ejemplo n.º 3
0
func Run(port uint16) {
	//start := time.Now()
	err := posts.Init("posts")

	ipCircBuffer.Init()

	db.Open()
	defer db.Close()

	if err != nil {
		log.Println(err)
	}
	//log.Println("Took %s", time.Now().Sub(start))
	//log.Println(post)
	r := mux.NewRouter()
	r.HandleFunc("/posts", Log(getPostList))
	r.HandleFunc("/posts/{Title}", Log(getPost))
	r.HandleFunc("/posts/{Title}/paragraph/{id:[0-9]+}", Log(getParagraph)).Methods("GET")
	r.HandleFunc("/posts/{Title}/info", Log(getInfo)).Methods("GET")
	r.HandleFunc("/desktopIP", Log(getDesktopIP)).Methods("GET")
	r.HandleFunc("/desktopIP", Log(postDesktopIP)).Methods("POST")
	r.HandleFunc("/desktopIP", Log(clearDesktopIP)).Methods("DELETE")
	r.HandleFunc("/raspberryIP", Log(getRaspberryIP)).Methods("GET")
	r.HandleFunc("/raspberryIP", Log(postRaspberryIP)).Methods("POST")
	r.HandleFunc("/raspberryIP", Log(clearRaspberryIP)).Methods("DELETE")
	r.HandleFunc("/requestCount", Log(get24HourRequests)).Methods("GET")
	r.HandleFunc("/shortlink", Log(redirectToShortlink)).Methods("GET")
	r.HandleFunc("/shortlink/", Log(redirectToShortlink)).Methods("GET")
	r.HandleFunc("/shortlink", Log(makeShortlink)).Methods("POST")
	r.HandleFunc("/shortlink/{linkID}", Log(getShortlink)).Methods("GET")
	r.HandleFunc("/upload", Log(upload)).Methods("POST")
	// r.HandleFunc("/shortlink/{linkID}", deleteShortlink).Methods("DELETE")

	for {
		log.Printf("Running at 0.0.0.0:%d\n", port)
		log.Println(http.ListenAndServe(fmt.Sprintf("0.0.0.0:%d", port), r))
		time.Sleep(1 * time.Second)
	}
}