// Run configured API service on the configured port. If you Registers // middlewear for gziped responses and graceful shutdown with a 10 // second timeout. func (a *APIApp) Run() error { var err error if !a.isResolved { err = a.Resolve() } n := negroni.New() for _, m := range a.middleware { n.Use(m) } n.UseHandler(a.router) listenOn := strings.Join([]string{a.address, strconv.Itoa(a.port)}, ":") grip.Noticeln("starting app on:", listenOn) graceful.Run(listenOn, 10*time.Second, n) return err }
func (self *RstBuilder) Write(fn string) error { lines, err := self.GetLines() if err != nil { return err } dirName := filepath.Dir(fn) err = os.MkdirAll(dirName, 0755) if err == nil { grip.Noticeln("created directory:", dirName) } else { grip.Warning(err.Error()) } file, err := os.Create(fn) if err != nil { return err } defer file.Close() w := bufio.NewWriter(file) catcher := grip.NewCatcher() var numBytes int for _, line := range lines { nb, err := fmt.Fprintln(w, line) numBytes += nb catcher.Add(err) } catcher.Add(w.Flush()) if catcher.HasErrors() == false { grip.Debugf("wrote %d bytes to file '%f'.", numBytes, fn) } return catcher.Resolve() }