本文整理汇总了Golang中github.com/fragmenta/server.Server.Production方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.Production方法的具体用法?Golang Server.Production怎么用?Golang Server.Production使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/fragmenta/server.Server
的用法示例。
在下文中一共展示了Server.Production方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Setup
// Setup authentication and authorization keys for this app
func Setup(s *server.Server) {
// Set up our secret keys which we take from the config
// NB these are hex strings which we convert to bytes, for ease of presentation in secrets file
c := s.Configuration()
auth.HMACKey = auth.HexToBytes(c["hmac_key"])
auth.SecretKey = auth.HexToBytes(c["secret_key"])
auth.SessionName = "sendto"
// Enable https cookies on production server - we don't have https, so don't do this
if s.Production() {
s.Log("Using secure cookies")
auth.SecureCookies = true
}
}
示例2: Setup
// Setup sets up our application
func Setup(server *server.Server) {
// Setup log
server.Logger = log.New(server.Config("log"), server.Production())
// Set up our assets
setupAssets(server)
// Setup our view templates
setupView(server)
// Setup our database
setupDatabase(server)
// Routing
router, err := router.New(server.Logger, server)
if err != nil {
server.Fatalf("Error creating router %s", err)
}
// Setup our authentication and authorisation
authorise.Setup(server)
// Add a prefilter to store the current user on the context, so that we only fetch it once
// We use this below in Resource, and also in views to determine current user attributes
router.AddFilter(authorise.CurrentUserFilter)
// Add an authenticity token filter to write out a secret token for each request (CSRF protection)
router.AddFilter(authorise.AuthenticityTokenFilter)
// Setup our router and handlers
setupRoutes(router)
}
示例3: setupView
func setupView(server *server.Server) {
defer server.Timef("#info Finished loading templates in %s", time.Now())
view.Production = server.Production()
err := view.LoadTemplates()
if err != nil {
server.Fatalf("Error reading templates %s", err)
}
}
示例4: setupView
func setupView(server *server.Server) {
defer server.Timef("#info Finished loading templates in %s", time.Now())
// A very limited translation - would prefer to use editable.js
// instead and offer proper editing TODO: move to editable.js instead
view.Helpers["markup"] = markup
view.Helpers["timeago"] = timeago
view.Production = server.Production()
err := view.LoadTemplates()
if err != nil {
server.Fatalf("Error reading templates %s", err)
}
}
示例5: setupServices
// setupServices sets up external services from our config file
func setupServices(server *server.Server) {
// Don't send if not on production server
if !server.Production() {
return
}
config := server.Configuration()
context := schedule.NewContext(server.Logger, server)
now := time.Now().UTC()
// Set up twitter if available, and schedule tweets
if config["twitter_secret"] != "" {
twitter.Setup(config["twitter_key"], config["twitter_secret"], config["twitter_token"], config["twitter_token_secret"])
tweetTime := time.Date(now.Year(), now.Month(), now.Day(), 9, 0, 0, 0, time.UTC)
tweetInterval := 5 * time.Hour
// For testing
//tweetTime = now.Add(time.Second * 5)
schedule.At(storyactions.TweetTopStory, context, tweetTime, tweetInterval)
}
// Set up mail
if config["mail_secret"] != "" {
mail.Setup(config["mail_secret"], config["mail_from"])
// Schedule emails to go out at 09:00 every day, starting from the next occurance
emailTime := time.Date(now.Year(), now.Month(), now.Day(), 10, 10, 10, 10, time.UTC)
emailInterval := 7 * 24 * time.Hour // Send Emails weekly
// For testing send immediately on launch
//emailTime = now.Add(time.Second * 2)
schedule.At(useractions.DailyEmail, context, emailTime, emailInterval)
}
}
示例6: Setup
// Setup sets up our application
func Setup(server *server.Server) {
// Setup log
server.Logger = log.New(server.Config("log"), server.Production())
// Set up our assets
setupAssets(server)
// Setup our view templates
setupView(server)
// Setup our database
setupDatabase(server)
// Routing
router, err := router.New(server.Logger, server)
if err != nil {
server.Fatalf("Error creating router %s", err)
}
// Setup our router and handlers
setupRoutes(router)
}