예제 #1
0
func main() {

	flag.Parse()
	cpus := runtime.NumCPU()
	runtime.GOMAXPROCS(cpus)

	log.SetFormatter(&log.JSONFormatter{})
	log.SetOutput(os.Stderr)
	if *env == "production" {
		log.SetLevel(log.WarnLevel)
	} else {
		log.SetLevel(log.DebugLevel)
	}
	log.Infoln("Starting server...")

	// load config
	d, err := ioutil.ReadFile(*configFile)
	if err != nil {
		log.Fatalln("[ERROR] read config.yml", err)
	}

	cfg, err := config.Load(bytes.NewReader(d), *env)
	if err != nil {
		log.Fatalln("[ERROR] config Load", err)
	}
	psAll := sphinx.NewSphinx(cfg.PSConfig, cpus)

	ctx := context.Background()
	ctx = sphinx.NewContext(ctx, psAll)
	kami.Context = ctx
	kami.Serve()
}
예제 #2
0
파일: main.go 프로젝트: keichi/scribble
func main() {
	dbMap := InitDB()
	defer dbMap.Db.Close()
	dbMap.TraceOn("[gorp]", log.New(os.Stdout, "scribble: ", log.Lmicroseconds))

	ctx := context.Background()
	kami.Context = context.WithValue(ctx, "db", dbMap)

	// Middlwares
	kami.Use("/api/", auth.AuthMiddleware)

	// Authentication APIs
	kami.Post("/api/register", handler.Register)
	kami.Post("/api/login", handler.Login)
	kami.Post("/api/logout", handler.Logout)

	// Note APIs
	kami.Get("/api/notes", handler.ListNotes)
	kami.Post("/api/notes", handler.AddNote)
	kami.Get("/api/notes/:noteId", handler.GetNote)
	kami.Put("/api/notes/:noteId", handler.UpdateNote)
	kami.Delete("/api/notes/:noteId", handler.DeleteNote)

	kami.Serve()
}
예제 #3
0
func main() {
	cpus := runtime.NumCPU()
	runtime.GOMAXPROCS(cpus)
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)

	ctx := context.Background()
	ctx = NewContext(ctx)

	ctx = WithAuthCallbackFunc(ctx, func(ctx context.Context, w http.ResponseWriter, r *http.Request, token *oauth2.Token) {
		fmt.Println(token.AccessToken)
	})
	ctx = WithAuthErrorFunc(ctx, func(ctx context.Context, w http.ResponseWriter, r *http.Request, err error) {
		fmt.Println(err)
		w.Write([]byte(err.Error()))
	})

	kami.Context = ctx

	kami.Get("/login/paypal", LoginPayPal)
	kami.Get("/auth/paypal/callback", AuthPayPalCallback)
	kami.Get("/payment/create", PaymentCreate)
	kami.Get("/payment/done", PaymentDone)
	kami.Get("/paypal/payment/execute", PayPalPaymentExecute)
	kami.Get("/paypal/payment/cancel", PayPalPaymentCancel)

	log.Println("Starting server...")
	log.Println("GOMAXPROCS: ", cpus)
	kami.Serve()
}
예제 #4
0
func main() {
	c := cron.New()
	c.AddFunc("5 * * * * *", Hoge)   // 毎分5秒
	c.AddFunc("*/5 * * * * *", Fuga) // 5秒毎

	c.Start()
	isRunning := true

	kami.Get("/", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("OK"))
	})
	kami.Get("/start", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		if !isRunning {
			c.Start()
			isRunning = true
		}
		w.Write([]byte("START OK"))
	})
	kami.Get("/stop", func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
		if isRunning {
			c.Stop()
			isRunning = false
		}
		w.Write([]byte("STOP OK"))
	})

	defer func() {
		if isRunning {
			c.Stop()
			isRunning = false
		}
	}()

	kami.Serve()
}
예제 #5
0
파일: server.go 프로젝트: misakik/f3
func main() {
	flag.Parse()

	switch flag.Arg(0) {

	case "index":
		search.Index(flag.Arg(1))

	case "search":
		search.OpenIndex()

		result, err := search.Search(flag.Arg(1))
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println(result)

	case "server":
		search.OpenIndex()

		kami.Get("/search/:keyword", searchHandler)
		kami.Serve()
	}
}
예제 #6
0
func main() {
	ctx := context.Background()
	kami.Context = ctx // set our "god context", the base context for all requests

	kami.Use("/", greetMiddleware)  // use this middleware for paths under /hello/
	kami.Get("/hello/:name", greet) // add a GET handler with a parameter in the URL
	kami.Serve()                    // gracefully serve with support for einhorn and systemd
}
예제 #7
0
func main() {
	ctx := context.Background()
	kami.Context = ctx

	kami.PanicHandler = PanicHandler
	kami.Get("/", index)

	kami.Serve()
}
func main() {
	ctx := context.Background()
	kami.Context = ctx

	log.Println("start dispatcher...")
	StartDispatcher(2048)

	kami.Post("/work", greet)
	kami.Serve()
}
예제 #9
0
func main() {
	ctx := context.Background()
	kami.Context = ctx

	kami.PanicHandler = PanicHandler
	kami.Get("/", index)

	rollbar.Message(rollbar.INFO, "test")

	kami.Serve()
}
예제 #10
0
func main() {
	var err error
	db, err = sql.Open("mysql", connectionString)
	if err != nil {
		log.Fatalf("Error opening database: %v", err)
	}
	db.SetMaxIdleConns(maxConnectionCount)

	flag.Set("bind", ":8080")

	kami.Use("/", serverMiddleware)
	kami.Get("/json", jsonHandler)
	kami.Get("/db", dbHandler)
	kami.Get("/queries", queriesHandler)
	kami.Get("/fortunes", fortuneHandler)
	kami.Get("/updates", updateHandler)
	kami.Get("/plaintext", plaintextHandler)
	kami.Serve()
}
예제 #11
0
func main() {
	runtime.GOMAXPROCS(30)

	sig := make(chan os.Signal)
	signal.Notify(sig, os.Interrupt)
	signal.Notify(sig, syscall.SIGTERM)

	ctx := context.Background()
	kami.Context = ctx

	kami.Post("/work", work)

	go func() {
		kami.Serve()
	}()

	<-sig

}
예제 #12
0
func main() {
	var mongoUrl = flag.String("db", "petrucho-db", "MongoDB URL")
	flag.Parse()

	ctx := context.Background()
	ctx = db.OpenMongoDB(ctx, "main", *mongoUrl)
	defer db.Close(ctx)
	kami.Context = ctx

	secret := func(email, realm string) string {
		u := User{}
		users := userStorage(ctx)
		err := users.Find(bson.M{"email": email, "confirmed": true}).One(&u)
		if err != nil {
			return ""
		}
		return u.Password
	}

	authenticator := auth.NewBasicAuthenticator("Restricted", secret)

	kami.Get("/", homeHandler)
	kami.Get("/register", registrationForm)
	kami.Post("/register", registerUser)
	kami.Get("/confirm/:token", confirmRegistration)
	kami.Get("/users", viewAllUsers)
	kami.Get("/users/:email", viewUser)
	kami.Use("/users/:email/edit", func(ctx context.Context, w http.ResponseWriter, r *http.Request) context.Context {
		var username string
		authenticator.Wrap(func(w http.ResponseWriter, r *auth.AuthenticatedRequest) {
			username = r.Username
		})(w, r)
		if len(username) == 0 {
			return nil
		}
		return context.WithValue(ctx, "auth", username)
	})
	kami.Get("/users/:email/edit", editProfileForm)
	kami.Post("/users/:email/edit", updateProfile)

	kami.Serve()
}
예제 #13
0
파일: main.go 프로젝트: ysaito-lev218/todo
func main() {
	dbcon := PrePareDB()
	tmpls := template.Must(template.ParseGlob("./template/*.html"))

	ctx := context.Background()
	ctx = db.WithSQL(ctx, "main", dbcon)
	ctx = view.NewContext(ctx, tmpls)

	// dbを閉じる
	defer db.CloseSQLAll(ctx)

	// 神コンテキスト!
	kami.Context = ctx

	kami.Get("/", todo.Index)
	kami.Post("/create", todo.Create)
	kami.Post("/finish", todo.Finish)
	kami.Post("/delete", todo.Delete)

	kami.Serve()
}
예제 #14
0
파일: kami.go 프로젝트: konjoot/try-kami
func main() {
	loadKami(github.API)
	kami.Serve()
}
예제 #15
0
파일: main.go 프로젝트: konjoot/benches
func main() {
	kami.Get("/contacts", getContacts)
	kami.Serve()
}
예제 #16
0
파일: main.go 프로젝트: calebthompson/pgf
func main() {
	kami.Get("/", web.Form)
	kami.Post("/keyring", web.KeychainHandler)
	kami.Serve()
}
예제 #17
0
func main() {
	flag.Set("bind", ":1234")
	kami.Get("/hello/:name", hello)
	kami.Serve()
}