コード例 #1
0
ファイル: reminder.go プロジェクト: elimisteve/do_reminder
func main() {
	// Load DB
	options := &bolt.Options{Timeout: 2 * time.Second}
	dbPath := path.Join(os.Getenv("BOLT_PATH"), "reminder.db")
	db, err := bolt.Open(dbPath, 0600, options)
	if err != nil {
		log.Fatalf("Error opening bolt DB: %v", err)
	}
	defer db.Close()

	// Schedule all (non-cancelled) Reminders
	rems, err := remind.GetAllReminders(db)
	if err != nil {
		log.Fatalf("Error getting reminders: %v\n", err)
	}

	runningReminders.Schedule(db, rems)

	//
	// Router, etc
	//

	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Logger())
	m.Use(martini.Recovery())
	m.Action(r.Handle)

	m.Map(db)

	r.Post("/sms", incomingSMS)

	m.Run()
}
コード例 #2
0
ファイル: nrsc_example.go プロジェクト: Nitron/nrscstatic
func main() {
	m := martini.New()
	m.Use(martini.Recovery())
	m.Use(martini.Logger())
	m.Use(nrscstatic.NrscStatic("public", true))
	http.ListenAndServe(":8080", m)
}
コード例 #3
0
ファイル: gui.go プロジェクト: nbrownus/syncthing
func startGUI(cfg GUIConfiguration, m *Model) {
	router := martini.NewRouter()
	router.Get("/", getRoot)
	router.Get("/rest/version", restGetVersion)
	router.Get("/rest/model", restGetModel)
	router.Get("/rest/connections", restGetConnections)
	router.Get("/rest/config", restGetConfig)
	router.Get("/rest/config/sync", restGetConfigInSync)
	router.Get("/rest/system", restGetSystem)
	router.Get("/rest/errors", restGetErrors)

	router.Post("/rest/config", restPostConfig)
	router.Post("/rest/restart", restPostRestart)
	router.Post("/rest/reset", restPostReset)
	router.Post("/rest/error", restPostError)
	router.Post("/rest/error/clear", restClearErrors)

	go func() {
		mr := martini.New()
		if len(cfg.User) > 0 && len(cfg.Password) > 0 {
			mr.Use(basic(cfg.User, cfg.Password))
		}
		mr.Use(embeddedStatic())
		mr.Use(martini.Recovery())
		mr.Use(restMiddleware)
		mr.Action(router.Handle)
		mr.Map(m)
		err := http.ListenAndServe(cfg.Address, mr)
		if err != nil {
			warnln("GUI not possible:", err)
		}
	}()
}
コード例 #4
0
ファイル: gui.go プロジェクト: ngpestelos/syncthing
func startGUI(addr string, m *Model) {
	router := martini.NewRouter()
	router.Get("/", getRoot)
	router.Get("/rest/version", restGetVersion)
	router.Get("/rest/model", restGetModel)
	router.Get("/rest/connections", restGetConnections)
	router.Get("/rest/config", restGetConfig)
	router.Get("/rest/config/sync", restGetConfigInSync)
	router.Get("/rest/need", restGetNeed)
	router.Get("/rest/system", restGetSystem)
	router.Get("/rest/errors", restGetErrors)

	router.Post("/rest/config", restPostConfig)
	router.Post("/rest/restart", restPostRestart)
	router.Post("/rest/error", restPostError)

	go func() {
		mr := martini.New()
		mr.Use(embeddedStatic())
		mr.Use(martini.Recovery())
		mr.Action(router.Handle)
		mr.Map(m)
		err := http.ListenAndServe(addr, mr)
		if err != nil {
			warnln("GUI not possible:", err)
		}
	}()
}
コード例 #5
0
ファイル: server.go プロジェクト: rupakg/pmxadapter
// NewServer creates an instance of a martini server. The
// adapterInst parameter is the adapter type the server will
// use when dispatching requests.
func NewServer(adapterInst PanamaxAdapter) AdapterServer {
	s := martini.New()

	// Setup middleware
	s.Use(martini.Recovery())
	s.Use(martini.Logger())
	s.Use(mapEncoder)
	s.Use(func(c martini.Context, w http.ResponseWriter, r *http.Request) {
		c.Map(adapterInst)
	})
	// Setup routes
	router := martini.NewRouter()
	router.Group(fmt.Sprintf("/%s", APIVersion), func(r martini.Router) {
		r.Get(`/services`, getServices)
		r.Get(`/services/:id`, getService)
		r.Post(`/services`, createServices)
		r.Put(`/services/:id`, updateService)
		r.Delete(`/services/:id`, deleteService)
		r.Get(`/metadata`, getMetadata)
	})

	// Add the router action
	s.Action(router.Handle)
	server := martiniServer{svr: s}

	return &server
}
コード例 #6
0
ファイル: gui.go プロジェクト: JoeX2/syncthing
func startGUI(addr string, m *model.Model) {
	router := martini.NewRouter()
	router.Get("/", getRoot)
	router.Get("/rest/version", restGetVersion)
	router.Get("/rest/model", restGetModel)
	router.Get("/rest/connections", restGetConnections)
	router.Get("/rest/config", restGetConfig)
	router.Get("/rest/need", restGetNeed)
	router.Get("/rest/system", restGetSystem)

	fs, err := embed.Unpack(Resources)
	if err != nil {
		panic(err)
	}

	go func() {
		mr := martini.New()
		mr.Use(embeddedStatic(fs))
		mr.Use(martini.Recovery())
		mr.Action(router.Handle)
		mr.Map(m)
		err := http.ListenAndServe(addr, mr)
		if err != nil {
			warnln("GUI not possible:", err)
		}
	}()

}
コード例 #7
0
func main() {
	Db = dbSetup()

	m := martini.New()
	//m.Use(martini.Logger())
	m.Use(martini.Recovery())
	m.Action(routes().Handle)
	m.Run()
}
コード例 #8
0
ファイル: web.go プロジェクト: josephyzhou/gogs
func newMartini() *martini.ClassicMartini {
	r := martini.NewRouter()
	m := martini.New()
	m.Use(middleware.Logger())
	m.Use(martini.Recovery())
	m.Use(martini.Static("public"))
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)
	return &martini.ClassicMartini{m, r}
}
コード例 #9
0
func newModern() *Modern { // customized martini.Classic
	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Recovery())
	m.Action(r.Handle)

	return &Modern{
		Martini: m,
		Router:  r,
	}
}
コード例 #10
0
ファイル: main.go プロジェクト: pkieltyka/purls-server
func main() {
	// runtime.GOMAXPROCS(runtime.NumCPU())
	// fmt.Printf("GOMAXPROCS is %d\n", runtime.GOMAXPROCS(0))

	// Server and middleware
	m := martini.New()
	m.Use(martini.Logger())
	m.Use(martini.Recovery())

	r := martini.NewRouter()
	m.Action(r.Handle)

	r.Get("/", func() string {
		return "."
	})

	r.Any("/fetch", func(req *http.Request, res http.ResponseWriter) {
		err := req.ParseForm()
		if err != nil {
			renderMsg(res, 422, "Unable to parse parameters")
			return
		}

		// Grab params and set defaults
		urls := req.Form["url"]
		if len(urls) == 0 {
			urls = req.Form["url[]"]
		}
		maxtime, _ := strconv.Atoi(req.Form.Get("maxtime"))
		if maxtime == 0 {
			maxtime = MAXTIME
		}
		if len(urls) == 0 {
			renderMsg(res, 422, "Url parameter required")
			return
		}

		responses := httpFetch(urls, maxtime)

		if err != nil {
			renderMsg(res, 500, err.Error())
		} else {
			renderMsg(res, 200, responses)
		}
	})

	// Boot the server
	log.Println("** Purls", VERSION, "http server listening on", ADDR)
	log.Println("** with thruput:", THRUPUT, "maxtime:", MAXTIME)

	if err := http.ListenAndServe(ADDR, m); err != nil {
		log.Fatal(err)
	}
}
コード例 #11
0
ファイル: server.go プロジェクト: h12w/golang-rest-server
func AppServer() *Server {
	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Logger())
	m.Use(martini.Recovery())
	m.Use(render.Renderer())
	m.Use(DB())

	m.Action(r.Handle)
	return &Server{m, r}
}
コード例 #12
0
func init() {
	m = martini.New()
	m.Use(martini.Recovery())
	m.Use(martini.Logger())
	m.Use(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("X-Frame-Options", "DENY")
		w.Header().Set("Strict-Transport-Security", "max-age=60000")
	})
	m.Use(martini.Static("public"))
	m.Use(func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
	})
	r := martini.NewRouter()
	r.Put("/candidates", mainHandler)
	m.Action(r.Handle)
	http.Handle("/", m)
}
コード例 #13
0
ファイル: middleware.go プロジェクト: eliothedeman/slides
func main() {

	// START OMIT
	m := martini.New()

	// Specify what middleware to use
	m.Use(martini.Logger())
	m.Use(martini.Recovery())

	r := martini.NewRouter()
	r.Get("/ok", ok)
	r.Get("/panic", panicFunc)
	m.MapTo(r, (*martini.Routes)(nil))
	m.Action(r.Handle)
	http.ListenAndServe(":1810", m)
	// STOP OMIT
}
コード例 #14
0
ファイル: tuplespaced.go プロジェクト: pombredanne/tuplespace
func makeService(ts tuplespace.RawTupleSpace, debug bool) *martini.Martini {
	m := martini.New()
	m.Use(martini.Recovery())
	if debug {
		m.Use(martini.Logger())
	}
	m.Use(server.SerializationMiddleware())

	m.MapTo(ts, (*tuplespace.RawTupleSpace)(nil))

	r := martini.NewRouter()
	r.Post("/tuplespace/", server.DeserializerMiddleware(SendRequest{}), Send)
	r.Get("/tuplespace/", server.DeserializerMiddleware(tuplespace.ReadRequest{}), Read)
	r.Delete("/tuplespace/", server.DeserializerMiddleware(tuplespace.ReadRequest{}), Take)

	m.Action(r.Handle)
	return m
}
コード例 #15
0
ファイル: server.go プロジェクト: huzorro/martini-api-example
func init() {
	m = martini.New()
	// Setup middleware
	m.Use(martini.Recovery())
	m.Use(martini.Logger())
	m.Use(auth.Basic(AuthToken, ""))
	m.Use(MapEncoder)
	// Setup routes
	r := martini.NewRouter()
	r.Get(`/albums`, GetAlbums)
	r.Get(`/albums/:id`, GetAlbum)
	r.Post(`/albums`, AddAlbum)
	r.Put(`/albums/:id`, UpdateAlbum)
	r.Delete(`/albums/:id`, DeleteAlbum)
	// Inject database
	m.MapTo(db, (*DB)(nil))
	// Add the router action
	m.Action(r.Handle)
}
コード例 #16
0
func init() {
	m = martini.New()

	// middleware
	m.Use(martini.Recovery())
	m.Use(martini.Logger())

	// injection
	m.MapTo(&UnitRepository{Repository: Repository{Type: Unit{}, Table: "units"}}, (*IUnitRepository)(nil))

	// routes
	r := martini.NewRouter()
	r.Get("/unit/:id", GetUnit)
	r.Get("/unit", GetAllUnits)
	r.Post("/unit", binding.Bind(Unit{}), AddUnit)
	r.Put("/unit", binding.Bind(Unit{}), UpdateUnit)
	r.Delete("/unit/:id", DeleteUnit)

	// wireup router action
	m.Action(r.Handle)
}
コード例 #17
0
ファイル: gui.go プロジェクト: humanrelationshins/syncthing
func startGUI(cfg config.GUIConfiguration, m *model.Model) error {
	listener, err := net.Listen("tcp", cfg.Address)
	if err != nil {
		return err
	}

	router := martini.NewRouter()
	router.Get("/", getRoot)
	router.Get("/rest/version", restGetVersion)
	router.Get("/rest/model", restGetModel)
	router.Get("/rest/connections", restGetConnections)
	router.Get("/rest/config", restGetConfig)
	router.Get("/rest/config/sync", restGetConfigInSync)
	router.Get("/rest/system", restGetSystem)
	router.Get("/rest/errors", restGetErrors)
	router.Get("/rest/discovery", restGetDiscovery)

	router.Post("/rest/config", restPostConfig)
	router.Post("/rest/restart", restPostRestart)
	router.Post("/rest/reset", restPostReset)
	router.Post("/rest/shutdown", restPostShutdown)
	router.Post("/rest/error", restPostError)
	router.Post("/rest/error/clear", restClearErrors)
	router.Post("/rest/discovery/hint", restPostDiscoveryHint)

	mr := martini.New()
	if len(cfg.User) > 0 && len(cfg.Password) > 0 {
		mr.Use(basic(cfg.User, cfg.Password))
	}
	mr.Use(static)
	mr.Use(martini.Recovery())
	mr.Use(restMiddleware)
	mr.Action(router.Handle)
	mr.Map(m)

	go http.Serve(listener, mr)

	return nil
}
コード例 #18
0
ファイル: todoapp.go プロジェクト: JamesClonk/todoapp
func setupMartini() *martini.Martini {
	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Recovery())
	m.Use(martini.Static("assets", martini.StaticOptions{SkipLogging: true})) // skip logging on static content
	m.Use(martini.Logger())
	m.Use(render.Renderer(render.Options{
		Directory:  "templates",
		Layout:     "layout",
		Extensions: []string{".html"},
		Delims:     render.Delims{"{[{", "}]}"},
		IndentJSON: true,
	}))
	m.Use(ConfigOptions(configFile))
	m.Use(TaskList())
	m.Map(log.New(os.Stdout, logPrefix, logFlags))
	m.Action(r.Handle)

	setupRoutes(r)

	return m
}
コード例 #19
0
func init() {
	m = martini.New()

	envEnvironment := os.Getenv("ENVIRONMENT")

	if envEnvironment == "" {
		envEnvironment = "development"
	}

	brokerConfig, _ = config.ParseFromYAMLFile(envEnvironment, "config/config.yml")
	b, _ = sqlbroker.New(brokerConfig)

	if brokerConfig.CFCCTarget != "" &&
		brokerConfig.CFUAATarget != "" &&
		brokerConfig.CFUser != "" &&
		brokerConfig.CFPassword != "" {

		registerCFServices = true
		var err error
		cfs, err = cfservices.New(brokerConfig.CFCCTarget, brokerConfig.CFUAATarget, brokerConfig.CFUser, brokerConfig.CFPassword)
		if err != nil {
			fmt.Println("Cannot connect to CF Services. - " + err.Error())
		}
	}

	m.Use(martini.Recovery())
	m.Use(martini.Logger())

	r := martini.NewRouter()
	r.Get(`/v2/catalog`, GetCatalog)
	r.Put(`/v2/service_instances/:id`, Provision)
	r.Delete(`/v2/service_instances/:id`, Deprovision)
	r.Put(`/v2/service_instances/:instance_id/service_bindings/:id`, Bind)
	r.Delete(`/v2/service_instances/:instance_id/service_bindings/:id`, Unbind)
	r.Put(`/v2/services/:service_id/plans`, AddPlan)
	r.Delete(`/v2/services/:service_id/plans/:plan_id`, DeletePlan)

	m.Action(r.Handle)
}
コード例 #20
0
ファイル: main.go プロジェクト: kopparam/pullprinting
func NewServer() *Server {
	var err error
	var s Server
	s.session, err = mgo.Dial("mongodb://*****:*****@localhost/test")
	if err != nil {
		fmt.Println("Cant connect to Mongo")
		panic(err)
	}
	s.db = s.session.DB("")
	s.gfs = s.db.GridFS("fs")

	s.m = martini.Classic()

	s.m.Handlers(martini.Recovery(), martini.Static("public"))

	//s.m.Get("/", func() {
	//	println(indexPage)
	//})
	s.registerHandlers()
	//s.m.Post("/filename/:filename", printFile)
	return &s
}
コード例 #21
0
ファイル: main.go プロジェクト: ryansb/legowebservices
func main() {
	log.UseStderr(true)
	log.SetV(9)
	flag.Parse()
	m := martini.New()
	m.Use(martini.Logger())
	m.Use(martini.Recovery())
	r := martini.NewRouter()

	tde := kv.NewTiedotEngine("./tiedotdb", []string{"short.url", "short.counter"}, kv.KeepIfExist)
	tde.AddIndex("short.url", kv.Path{"Short"})
	tde.AddIndex("short.counter", kv.Path{"Count"})

	if *useShort {
		log.Info("Starting LWS.short")
		s := short.NewShortener(tde)
		r.Any("/s", stripper("/s"), s.ServeHTTP)
		r.Any("/s/.*", stripper("/s"), s.ServeHTTP)
	}

	m.Action(r.Handle)
	http.ListenAndServe(*port, m)
}
コード例 #22
0
func main() {
	tc := twilio.NewClient(twilioAccount, twilioKey, nil)
	mc := mailgun.NewMailgun(emailDomain, mailgunKey, mailgunPublicKey)

	r := martini.NewRouter()
	m := martini.New()
	m.Use(martini.Logger())
	m.Use(martini.Recovery())
	m.Action(r.Handle)

	m.Map(tc)
	m.MapTo(mc, (*mailgun.Mailgun)(nil))

	r.Post("/call", verifyTwilioReq, incomingCall)
	r.Post("/record-voicemail", verifyTwilioReq, recordVoicemail)
	r.Post("/voicemail", verifyTwilioReq, incomingVoicemail)
	r.Post("/sms", verifyTwilioReq, incomingSMS)
	r.Post("/email", incomingEmail)
	r.Post("/hangup", hangup)
	r.Get("/ping", func() {})

	go pinger()
	m.Run()
}
コード例 #23
0
ファイル: wigo.go プロジェクト: root-gg/wigo
func threadHttp(config *wigo.HttpConfig) {
	apiAddress := config.Address
	apiPort := config.Port

	m := martini.New()

	if wigo.GetLocalWigo().GetConfig().Global.Debug {
		// Log requests
		m.Use(martini.Logger())
	}

	// Compress http responses with gzip
	if config.Gzip {
		log.Println("Http server : gzip compression enabled")
		m.Use(gzip.All())
	}

	// Add some basic security checks
	m.Use(secure.Secure(secure.Options{}))

	// Http basic auth
	if config.Login != "" && config.Password != "" {
		log.Println("Http server : basic auth enabled")
		m.Use(auth.Basic(config.Login, config.Password))
	}

	// Serve static files
	m.Use(martini.Static("public"))

	// Handle errors // TODO is this even working ?
	m.Use(martini.Recovery())

	// Define the routes.

	r := martini.NewRouter()

	r.Get("/api", func() (int, string) {
		json, err := wigo.GetLocalWigo().ToJsonString()
		if err != nil {
			return 500, fmt.Sprintf("%s", err)
		}
		return 200, json
	})

	r.Get("/api/status", func() string { return strconv.Itoa((wigo.GetLocalWigo().GlobalStatus)) })
	r.Get("/api/logs", wigo.HttpLogsHandler)
	r.Get("/api/logs/indexes", wigo.HttpLogsIndexesHandler)
	r.Get("/api/groups", wigo.HttpGroupsHandler)
	r.Get("/api/groups/:group", wigo.HttpGroupsHandler)
	r.Get("/api/groups/:group/logs", wigo.HttpLogsHandler)
	r.Get("/api/groups/:group/probes/:probe/logs", wigo.HttpLogsHandler)
	r.Get("/api/hosts", wigo.HttpRemotesHandler)
	r.Get("/api/hosts/:hostname", wigo.HttpRemotesHandler)
	r.Get("/api/hosts/:hostname/status", wigo.HttpRemotesStatusHandler)
	r.Get("/api/hosts/:hostname/logs", wigo.HttpLogsHandler)
	r.Get("/api/hosts/:hostname/probes", wigo.HttpRemotesProbesHandler)
	r.Get("/api/hosts/:hostname/probes/:probe", wigo.HttpRemotesProbesHandler)
	r.Get("/api/hosts/:hostname/probes/:probe/status", wigo.HttpRemotesProbesStatusHandler)
	r.Get("/api/hosts/:hostname/probes/:probe/logs", wigo.HttpLogsHandler)
	r.Get("/api/probes/:probe/logs", wigo.HttpLogsHandler)
	r.Get("/api/authority/hosts", wigo.HttpAuthorityListHandler)
	r.Post("/api/authority/hosts/:uuid/allow", wigo.HttpAuthorityAllowHandler)
	r.Post("/api/authority/hosts/:uuid/revoke", wigo.HttpAuthorityRevokeHandler)

	m.Use(func(c martini.Context, w http.ResponseWriter, r *http.Request) {
		if strings.HasPrefix(r.URL.Path, "/api") {
			w.Header().Set("Content-Type", "application/json")
		}
	})

	m.Action(r.Handle)

	// Create a listner and serv connections forever.
	if config.SslEnabled {
		address := apiAddress + ":" + strconv.Itoa(apiPort)
		log.Println("Http server : starting tls server @ " + address)
		tlsConfig := &tls.Config{MinVersion: tls.VersionTLS10}
		server := &http.Server{Addr: address, Handler: m, TLSConfig: tlsConfig}
		err := server.ListenAndServeTLS(config.SslCert, config.SslKey)
		if err != nil {
			log.Fatalf("Failed to start http server : %s", err)
		}
	} else {
		address := apiAddress + ":" + strconv.Itoa(apiPort)
		log.Println("Http server : starting plain http server @ " + address)
		if err := http.ListenAndServe(address, m); err != nil {
			log.Fatalf("Failed to start http server : %s", err)
		}
	}
}
コード例 #24
0
ファイル: gui.go プロジェクト: hdortez/syncthing
func startGUI(cfg config.GUIConfiguration, assetDir string, m *model.Model) error {
	var listener net.Listener
	var err error
	if cfg.UseTLS {
		cert, err := loadCert(confDir, "https-")
		if err != nil {
			newCertificate(confDir, "https-")
			cert, err = loadCert(confDir, "https-")
		}
		if err != nil {
			return err
		}
		tlsCfg := &tls.Config{
			Certificates: []tls.Certificate{cert},
			ServerName:   "syncthing",
		}
		listener, err = tls.Listen("tcp", cfg.Address, tlsCfg)
		if err != nil {
			return err
		}
	} else {
		listener, err = net.Listen("tcp", cfg.Address)
		if err != nil {
			return err
		}
	}

	if len(assetDir) > 0 {
		static = martini.Static(assetDir).(func(http.ResponseWriter, *http.Request, *log.Logger))
	} else {
		static = embeddedStatic()
	}

	router := martini.NewRouter()
	router.Get("/", getRoot)
	router.Get("/rest/version", restGetVersion)
	router.Get("/rest/model", restGetModel)
	router.Get("/rest/need", restGetNeed)
	router.Get("/rest/connections", restGetConnections)
	router.Get("/rest/config", restGetConfig)
	router.Get("/rest/config/sync", restGetConfigInSync)
	router.Get("/rest/system", restGetSystem)
	router.Get("/rest/errors", restGetErrors)
	router.Get("/rest/discovery", restGetDiscovery)
	router.Get("/qr/:text", getQR)

	router.Post("/rest/config", restPostConfig)
	router.Post("/rest/restart", restPostRestart)
	router.Post("/rest/reset", restPostReset)
	router.Post("/rest/shutdown", restPostShutdown)
	router.Post("/rest/error", restPostError)
	router.Post("/rest/error/clear", restClearErrors)
	router.Post("/rest/discovery/hint", restPostDiscoveryHint)

	mr := martini.New()
	if len(cfg.User) > 0 && len(cfg.Password) > 0 {
		mr.Use(basic(cfg.User, cfg.Password))
	}
	mr.Use(static)
	mr.Use(martini.Recovery())
	mr.Use(restMiddleware)
	mr.Action(router.Handle)
	mr.Map(m)

	go http.Serve(listener, mr)

	return nil
}
コード例 #25
0
ファイル: server.go プロジェクト: Bootz/nzbcrawler
func (s *Server) Init() {

	s.readConfig()

	store := sessions.NewCookieStore([]byte(s.Config2.Secret))
	store.Options(sessions.Options{
		Path:   "/",
		Domain: "",
		MaxAge: 86400 * 7,
	})

	//start Runner...
	if s.Config2.Crawl {
		runner = &Runner{s}
		go runner.Start()
	}

	cache = NewCache(s.Config2.Cachesize, s.Config2.Cachefree, true)

	i404, _ = ioutil.ReadFile("templates/static/images/404.jpg")

	m := martini.New()

	m.Map(s)

	m.Use(martini.Recovery())
	m.Use(martini.Static("templates/static"))
	m.Use(sessions.Sessions("top-kek", store))

	r := martini.NewRouter()
	r.Get("/", Auth, func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, "templates/index.html")
	})
	r.Get("/db/events/:offset/:tags/:name", Auth, GetReleaseWithTagAndName)
	r.Get("/db/event/:checksum/link", Auth, LinkFollow)
	r.Get("/db/event/:checksum/image", Auth, ServeImage)
	r.Get("/db/event/:checksum/score/:score", Auth, LinkFollow)
	r.Get("/log", Auth, func(w http.ResponseWriter, r *http.Request) {
		http.ServeFile(w, r, "templates/log.html")
	})
	r.Get("/log/cache", Auth, func() string {
		return fmt.Sprintf("{ \"count\": %v, \"size\": %v }", cache.GetSize(), cache.GetSizeInMb())
	})
	r.Get("/log/:offset/", Auth, GetLogs)
	r.Get("/log/:offset/:level", Auth, GetLogsWithLevel)
	r.Post("/log/clearlogs", Auth, func(server *Server) string {
		server.LogDB.Exec("drop table log")
		server.LogDB.AddTableWithName(mydb.Log{}, "log").SetKeys(true, "Uid")
		server.LogDB.CreateTablesIfNotExists()
		server.LogDB.Exec("vacuum")
		return ""
	})

	r.Get("/key/:key", func(res http.ResponseWriter, req *http.Request, server *Server, session sessions.Session, parms martini.Params) {
		key := parms["key"]
		if key == server.Config2.Key {
			log.Info("Login success from %v", req.RemoteAddr)
			session.Set("login", true)
			http.Redirect(res, req, "/", http.StatusFound)
		} else {
			log.Info("Login fail from %v", req.RemoteAddr)
			http.Error(res, "forbidden", http.StatusForbidden)
		}
	})

	m.Action(r.Handle)

	log.Info("listening on %v:%v", s.Config2.Host, s.Config2.Port)
	http.ListenAndServe(s.Config2.Host+":"+s.Config2.Port, m)
}