| // Copyright 2017 The Go Authors. All rights reserved. |
| // |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file or at |
| // https://developers.google.com/open-source/licenses/bsd. |
| |
| // Command gddo-server is the GoPkgDoc server. |
| package main |
| |
| import ( |
| "context" |
| "log" |
| "net/http" |
| "os" |
| "time" |
| |
| "github.com/golang/gddo/doc" |
| ) |
| |
| func main() { |
| ctx := context.Background() |
| v, err := loadConfig(ctx, os.Args) |
| if err != nil { |
| log.Fatal(ctx, "load config", "error", err.Error()) |
| } |
| doc.SetDefaultGOOS(v.GetString(ConfigDefaultGOOS)) |
| |
| s, err := newServer(ctx, v) |
| if err != nil { |
| log.Fatal("error creating server:", err) |
| } |
| |
| go func() { |
| for range time.Tick(s.v.GetDuration(ConfigCrawlInterval)) { |
| if err := s.doCrawl(ctx); err != nil { |
| log.Printf("Task Crawl: %v", err) |
| } |
| } |
| }() |
| go func() { |
| for range time.Tick(s.v.GetDuration(ConfigGithubInterval)) { |
| if err := s.readGitHubUpdates(ctx); err != nil { |
| log.Printf("Task GitHub updates: %v", err) |
| } |
| } |
| }() |
| http.Handle("/", s) |
| log.Fatal(http.ListenAndServe(s.v.GetString(ConfigBindAddress), s)) |
| } |