func init() { // Check the github repo and set these options properly when the site // goes live. secureOpts = secure.New(secure.Options{ AllowedHosts: []string{"localhost"}, SSLRedirect: false, SSLHost: "ssl.example.com", SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"}, STSSeconds: 315360000, STSIncludeSubdomains: true, STSPreload: true, FrameDeny: true, ContentTypeNosniff: true, BrowserXssFilter: true, // ContentSecurityPolicy: "default-src 'self'", IsDevelopment: true, }) // Logging (in conjunction with compression). opts := useful.DefaultOptions() opts.LogDestination = useful.File opts.LogName = filepath.Join("log", "access.log") opts.ArchiveDir = filepath.Join("log", "archives") useful.LogFile.Init(opts) cleanup.Register("glog", glog.Flush) // Make sure logs flush before we exit. cleanup.Register("useful", useful.LogFile.Close) // Close our log file. }
func init() { // Generate the reverse of our enum so we can work backwards and reload // a file with the name instead of the enum. // // The issue arises because we've decided to use an array instead of a map // to describe our in-memory templates. While this is more efficient, it // causes issues with our hot reloading because the name of the file // given to us from inotify is the string representation of the file's // name, and we can't match that up with the enum on the fly (or generate // code that does that using //go: generate). So, we run an init func that // generates a map of the names to the enum so we can work backwards to // reload the file. for i := 0; i < len(_TmplName_index)-1; i++ { key := _TmplName_name[_TmplName_index[i]:_TmplName_index[i+1]] TmplMap[key] = TmplName(i) } // Set up our watcher for hot reloads of modified files. watcher, err := inotify.NewWatcher() if err != nil { glog.Fatalln(err) } err = watcher.Watch(templatePath) if err != nil { glog.Fatalln(err) } Tmpls.Watcher = watcher Tmpls.Watch() cleanup.Register("reload", watcher.Close) // Close watcher. }