func runBe(configPath string) { var config pb.BackendConfig readConfig(configPath, &config) if config.ServePath == "" { glog.Fatal("No serving path was given in config.serve_path.") } srvConfig := config.GetServer() glog.Infof("Serving path %v", config.ServePath) l, err := net.Listen("tcp", srvConfig.Addr) if err != nil { glog.Fatalf("Failed to listen on %v: %v", srvConfig.Addr, err) } defer l.Close() glog.Infof("Listening for requests on %v", l.Addr()) go updateFrontendPort(NewAEADOrDie(config.PortKey), l.Addr(), config.PortUpdateUrl) server := &http.Server{ Handler: getBackendHTTPMux(&config), } if t := srvConfig.GetTls(); t != nil { l = tls.NewListener(l, BackendTLSConfigOrDie(t)) } else if srvConfig.GetInsecure() { PrintServerInsecureWarning() } else { glog.Fatalf("The config must specify one of 'insecure' or 'tls'") } glog.Fatal(server.Serve(l)) }
func (asset *Asset) Save(session *gocql.Session) error { if asset.Id.Timestamp() == 0 { asset.Id = gocql.TimeUUID() if err := session.Query(`INSERT INTO assets (id, name, path, contenttype, createdat, binary) VALUES (?, ?, ?, ?, ?, ?)`, asset.Id, asset.Name, strings.Join(asset.Path, ","), asset.ContentType, asset.CreatedAt, asset.Binary).Exec(); err != nil { glog.Fatal(err) return err } if err := session.Query(`INSERT INTO assetbypaths (path, id, name) VALUES (?, ?, ?)`, strings.Join(asset.Path, ","), asset.Id, asset.Name).Exec(); err != nil { glog.Fatal(err) return err } return nil } else { if err := session.Query(`UPDATE assets SET name = ?, path = ?, contenttype = ? WHERE id = ?`, asset.Name, strings.Join(asset.Path, ","), asset.ContentType, asset.Id).Exec(); err != nil { glog.Fatal(err) return err } if err := session.Query(`UPDATE assetbypaths SET name = ?, path = ? WHERE id = ?`, asset.Name, strings.Join(asset.Path, ","), asset.Id).Exec(); err != nil { glog.Fatal(err) return err } return nil } }
func main() { flag.Parse() storageDriver, err := NewStorageDriver(*argDbDriver) if err != nil { glog.Fatalf("Failed to connect to database: %s", err) } containerManager, err := manager.New(storageDriver) if err != nil { glog.Fatalf("Failed to create a Container Manager: %s", err) } // Register Docker. if err := docker.Register(containerManager); err != nil { glog.Errorf("Docker registration failed: %v.", err) } // Register the raw driver. if err := raw.Register(containerManager); err != nil { glog.Fatalf("raw registration failed: %v.", err) } // Handler for static content. http.HandleFunc(static.StaticResource, func(w http.ResponseWriter, r *http.Request) { err := static.HandleRequest(w, r.URL) if err != nil { fmt.Fprintf(w, "%s", err) } }) // Register API handler. if err := api.RegisterHandlers(containerManager); err != nil { glog.Fatalf("failed to register API handlers: %s", err) } // Redirect / to containers page. http.Handle("/", http.RedirectHandler(pages.ContainersPage, http.StatusTemporaryRedirect)) // Register the handler for the containers page. http.HandleFunc(pages.ContainersPage, func(w http.ResponseWriter, r *http.Request) { err := pages.ServerContainersPage(containerManager, w, r.URL) if err != nil { fmt.Fprintf(w, "%s", err) } }) defer glog.Flush() go func() { glog.Fatal(containerManager.Start()) }() glog.Infof("Starting cAdvisor version: %q", info.VERSION) glog.Infof("About to serve on port ", *argPort) addr := fmt.Sprintf(":%v", *argPort) glog.Fatal(http.ListenAndServe(addr, nil)) }
func (tunnel *Tunnel) RunV2() { addr := fmt.Sprintf(":%d", config.tunnel_port_v2) laddr, err := net.ResolveUDPAddr("udp", addr) if err != nil { log.Fatal("resolve udp addr err:", err) } conn, err := net.ListenUDP("udp", laddr) if err != nil { log.Fatal("listen upd err:", err) } buff := make([]byte, 64*1024) for { n, raddr, err := conn.ReadFromUDP(buff) if err != nil { log.Warning("read udp err:", err) continue } tunnel.HandleData(buff[:n], raddr, conn) tunnel.GC() } }
func HandleSignals(shutdownc <-chan io.Closer) { c := make(chan os.Signal, 1) signal.Notify(c, syscall.SIGHUP) signal.Notify(c, syscall.SIGINT) for { sig := <-c sysSig, ok := sig.(syscall.Signal) if !ok { glog.Fatal("Not a unix signal") } switch sysSig { case syscall.SIGHUP: case syscall.SIGINT: glog.Warningln("Got SIGTERM: shutting down") donec := make(chan bool) go func() { cl := <-shutdownc if err := cl.Close(); err != nil { exitf("Error shutting down: %v", err) } donec <- true }() select { case <-donec: glog.Infoln("Shut down completed.") os.Exit(0) case <-time.After(5 * time.Second): exitf("Timeout shutting down. Exiting uncleanly.") } default: glog.Fatal("Received another signal, should not happen.") } } }
// ListenAndServeKubeletServer initializes a server to respond to HTTP network requests on the Kubelet. func ListenAndServeKubeletServer( host HostInterface, resourceAnalyzer stats.ResourceAnalyzer, address net.IP, port uint, tlsOptions *TLSOptions, auth AuthInterface, enableDebuggingHandlers bool, runtime kubecontainer.Runtime) { glog.Infof("Starting to listen on %s:%d", address, port) handler := NewServer(host, resourceAnalyzer, auth, enableDebuggingHandlers, runtime) s := &http.Server{ Addr: net.JoinHostPort(address.String(), strconv.FormatUint(uint64(port), 10)), Handler: &handler, ReadTimeout: 60 * time.Minute, WriteTimeout: 60 * time.Minute, MaxHeaderBytes: 1 << 20, } if tlsOptions != nil { s.TLSConfig = tlsOptions.Config glog.Fatal(s.ListenAndServeTLS(tlsOptions.CertFile, tlsOptions.KeyFile)) } else { glog.Fatal(s.ListenAndServe()) } }
func main() { chain := gost.NewProxyChain() if err := chain.AddProxyNodeString(options.ChainNodes...); err != nil { glog.Fatal(err) } chain.Init() var wg sync.WaitGroup for _, ns := range options.ServeNodes { serverNode, err := gost.ParseProxyNode(ns) if err != nil { glog.Fatal(err) } wg.Add(1) go func(node gost.ProxyNode) { defer wg.Done() certFile, keyFile := node.Get("cert"), node.Get("key") if certFile == "" { certFile = gost.DefaultCertFile } if keyFile == "" { keyFile = gost.DefaultKeyFile } cert, err := gost.LoadCertificate(certFile, keyFile) if err != nil { glog.Fatal(err) } server := gost.NewProxyServer(node, chain, &tls.Config{Certificates: []tls.Certificate{cert}}) glog.Fatal(server.Serve()) }(serverNode) } wg.Wait() }
func main() { flag.Parse() glog.Infof("Starting Goship...") ctx := context.Background() ctx, cancel := context.WithCancel(ctx) defer cancel() auth.Initialize(auth.User{Name: *defaultUser, Avatar: *defaultAvatar}, []byte(*cookieSessionHash)) h, err := buildHandler(ctx) if err != nil { glog.Fatal(err) } w := io.WriteCloser(os.Stdout) if *requestLog != "-" { w, err = os.OpenFile(*requestLog, os.O_APPEND|os.O_CREATE, 0644) if err != nil { glog.Fatalf("Cannot open request log %s: %v", *requestLog, err) } defer w.Close() } h = ghandlers.CombinedLoggingHandler(w, h) fmt.Printf("Running on %s\n", *bindAddress) s := &http.Server{ Addr: *bindAddress, Handler: h, } if err := s.ListenAndServe(); err != nil { glog.Fatal(err) } }
// Connect to the database. func NewPostgresStorage() *PostgresStorage { postgresUrlString := os.Getenv("STORAGE_URL") if glog.V(2) { glog.Infoln("postgresUrlString: ", postgresUrlString) } if postgresUrlString == "" { glog.Fatal("STORAGE_URL cannot be empty.\nexport STORAGE_URL=postgres://user:password@host:port/db_name") } dataSource, err := pq.ParseURL(postgresUrlString) if err != nil { glog.Fatal("Could not read database string", err) } db, err := sql.Open("postgres", dataSource+" sslmode=disable fallback_application_name=bot") if err != nil { glog.Fatal("Could not connect to database.", err) } // The following 2 lines mitigate the leak of postgresql connection leak // explicitly setting a maximum number of postgresql connections db.SetMaxOpenConns(10) // explicitly setting a maximum number of Idle postgresql connections db.SetMaxIdleConns(2) return &PostgresStorage{db} }
func main() { flag.Parse() util.InitLogs() defer util.FlushLogs() if len(machineList) == 0 { glog.Fatal("No machines specified!") } var cloud cloudprovider.Interface switch *cloudProvider { case "gce": var err error cloud, err = cloudprovider.NewGCECloud() if err != nil { glog.Fatal("Couldn't connect to GCE cloud: %#v", err) } default: if len(*cloudProvider) > 0 { glog.Infof("Unknown cloud provider: %s", *cloudProvider) } else { glog.Info("No cloud provider specified.") } } var m *master.Master if len(etcdServerList) > 0 { m = master.New(etcdServerList, machineList, cloud) } else { m = master.NewMemoryServer(machineList, cloud) } glog.Fatal(m.Run(net.JoinHostPort(*address, strconv.Itoa(int(*port))), *apiPrefix)) }
func run(ctx *cli.Context) { // Init API api := New(Address) api.Init() log.Infof("Registering RPC Handler at %s", RPCPath) api.Handle(RPCPath, http.HandlerFunc(handler.RPC)) log.Infof("Registering API Handler at %s", APIPath) api.Handle(APIPath, http.HandlerFunc(restHandler)) // Initialise Server service := micro.NewService( micro.Name("go.micro.api"), ) // Start API if err := api.Start(); err != nil { log.Fatal(err) } // Run server if err := service.Run(); err != nil { log.Fatal(err) } // Stop API if err := api.Stop(); err != nil { log.Fatal(err) } }
func handleRequest(req msgs.ClientRequest) msgs.ClientResponse { glog.Info("Handling ", req.Request) // check if already applied found, res := c.Check(req) if found { glog.Info("Request found in cache") return res // FAST PASS } // CONSENESUS ALGORITHM HERE glog.Info("Passing request to consensus algorithm") cons_io.IncomingRequests <- req // wait for reply notifyclient_mutex.Lock() notifyclient[req] = make(chan msgs.ClientResponse) notifyclient_mutex.Unlock() reply := <-notifyclient[req] // check reply if reply.ClientID != req.ClientID { glog.Fatal("ClientID is different") } if reply.RequestID != req.RequestID { glog.Fatal("RequestID is different") } return reply }
func main() { pflag.CommandLine.AddGoFlagSet(flag.CommandLine) pflag.Parse() glog.Info("Starting HTTP server on port ", *argPort) defer glog.Flush() apiserverClient, err := CreateApiserverClient(*argApiserverHost, new(ClientFactoryImpl)) if err != nil { glog.Fatal(err) } serverAPIVersion, err := apiserverClient.ServerAPIVersions() if err != nil { glog.Fatal(err) } // Display Apiserver version. This is just for tests. println("Server API version: " + serverAPIVersion.GoString()) // Run a HTTP server that serves static public files from './public' and handles API calls. // TODO(bryk): Disable directory listing. http.Handle("/", http.FileServer(http.Dir("./public"))) http.Handle("/api/", CreateHttpApiHandler(apiserverClient)) glog.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *argPort), nil)) }
func (s *ParallelShuffleFetcher) Fetch(shuffleId uint64, reduceId uint64, merge func(<-chan interface{})) { glog.Infof("Fetching outputs for shuffle %d, reduce %d", shuffleId, reduceId) serverUris := _env.mapOutputTracker.GetServerUris(shuffleId) if serverUris == nil || len(serverUris) == 0 { return } type _Part struct { Idx int Uri string } urisLen := len(serverUris) parts := make([]_Part, urisLen) perm := rand.Perm(urisLen) //shuffle uris responses := make([]chan interface{}, urisLen) for i, v := range perm { u := serverUris[i] parts[v] = _Part{ Idx: i, Uri: u, } responses[i] = make(chan interface{}) } go func() { for _, v := range parts { part, uri := v.Idx, v.Uri req := &_FetcherRequest{ uri: uri, shuffleId: shuffleId, part: part, reduceId: reduceId, response: responses[part], } s.requests <- req } }() wg := new(sync.WaitGroup) for i := 0; i < urisLen; i++ { wg.Add(1) go func(idx int) { defer wg.Done() resp := <-responses[idx] if err, ok := resp.(error); ok { glog.Fatal(err) } else if vals, ok := resp.(map[int]interface{}); ok { ch := make(chan interface{}) go func() { defer close(ch) for _, v := range vals { ch <- v } }() merge(ch) } else { glog.Fatal("we do not know it.") } }(i) } wg.Wait() }
func main() { glog.Info("Web Server:Loading...") b := flag.Bool("benchmark", false, "") runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() if *b { glog.Info("Benchmark Mode") // Creat a file f, err := os.Create("pprof") if err != nil { glog.Fatal(err) } if err = pprof.StartCPUProfile(f); err != nil { glog.Fatal(err) } defer pprof.StopCPUProfile() } defer glog.Flush() glog.Info("Read the config.") if err := InitConf(); err != nil { glog.Fatal(err) } glog.Info("[Web]: listener start.") go start() signal.HandleSignal(signal.InitSignal()) }
func main() { glog.Info("Comet Server:Loading...") b := flag.Bool("benchmark", false, "") runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() if *b { glog.Info("Benchmark Mode") // Creat a file f, err := os.Create("pprof") if err != nil { glog.Fatal(err) } if err = pprof.StartCPUProfile(f); err != nil { glog.Fatal(err) } defer pprof.StopCPUProfile() } defer glog.Flush() glog.Info("Read the config.") if err := InitConf(); err != nil { glog.Fatal(err) } // Open the RPC listener. glog.Infof("Comet RPC Listen at:%v", Conf.RPC_addr) go listenRPC() // Open the cliens's server glog.Infof("Comet listen at: %v", Conf.Listen_addr) go startListen(CLIENT, Conf.Listen_addr) signal.HandleSignal(signal.InitSignal()) glog.Info("System exit.") }
func main() { flag.Parse() defer glog.Flush() reg := descriptor.NewRegistry() glog.V(1).Info("Processing code generator request") f := os.Stdin if *file != "stdin" { f, _ = os.Open("input.txt") } req, err := parseReq(f) if err != nil { glog.Fatal(err) } if req.Parameter != nil { for _, p := range strings.Split(req.GetParameter(), ",") { spec := strings.SplitN(p, "=", 2) if len(spec) == 1 { if err := flag.CommandLine.Set(spec[0], ""); err != nil { glog.Fatalf("Cannot set flag %s", p) } continue } name, value := spec[0], spec[1] if strings.HasPrefix(name, "M") { reg.AddPkgMap(name[1:], value) continue } if err := flag.CommandLine.Set(name, value); err != nil { glog.Fatalf("Cannot set flag %s", p) } } } g := genswagger.New(reg) reg.SetPrefix(*importPrefix) if err := reg.Load(req); err != nil { emitError(err) return } var targets []*descriptor.File for _, target := range req.FileToGenerate { f, err := reg.LookupFile(target) if err != nil { glog.Fatal(err) } targets = append(targets, f) } out, err := g.Generate(targets) glog.V(1).Info("Processed code generator request") if err != nil { emitError(err) return } emitFiles(out) }
func startSecureServing(opt *options.HeapsterRunOptions, handler http.Handler, promHandler http.Handler, mux *http.ServeMux, address string) { if len(opt.TLSClientCAFile) > 0 { authPprofHandler, err := newAuthHandler(opt, handler) if err != nil { glog.Fatalf("Failed to create authorized pprof handler: %v", err) } handler = authPprofHandler authPromHandler, err := newAuthHandler(opt, promHandler) if err != nil { glog.Fatalf("Failed to create authorized prometheus handler: %v", err) } promHandler = authPromHandler } mux.Handle("/", handler) mux.Handle("/metrics", promHandler) // If allowed users is set, then we need to enable Client Authentication if len(opt.AllowedUsers) > 0 { server := &http.Server{ Addr: address, Handler: mux, TLSConfig: &tls.Config{ClientAuth: tls.RequestClientCert}, } glog.Fatal(server.ListenAndServeTLS(opt.TLSCertFile, opt.TLSKeyFile)) } else { glog.Fatal(http.ListenAndServeTLS(address, opt.TLSCertFile, opt.TLSKeyFile, mux)) } }
func main() { flag.Parse() ok := true glog.Info("Processing code generator request") res, err := convertFrom(os.Stdin) if err != nil { ok = false if res == nil { message := fmt.Sprintf("Failed to read input: %v", err) res = &plugin.CodeGeneratorResponse{ Error: &message, } } } glog.Info("Serializing code generator response") data, err := proto.Marshal(res) if err != nil { glog.Fatal("Cannot marshal response", err) } _, err = os.Stdout.Write(data) if err != nil { glog.Fatal("Failed to write response", err) } if ok { glog.Info("Succeeded to process code generator request") } else { glog.Info("Failed to process code generator but successfully sent the error to protoc") os.Exit(1) } }
func main() { service := web.NewService( web.Name("go.micro.web.dashboard"), web.Version("latest"), ) service.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { log.Infof("%s '%s' for %s", r.Method, r.URL, r.RemoteAddr) http.ServeFile(w, r, "../dist/index.html") }) service.HandleFunc("/app.js", func(w http.ResponseWriter, r *http.Request) { log.Infof("%s '%s' for %s", r.Method, r.URL, r.RemoteAddr) http.ServeFile(w, r, "../dist/app.js") }) if err := service.Init(); err != nil { log.Fatal(err) } if err := service.Run(); err != nil { log.Fatal(err) } }
func main() { defer glog.Flush() flag.Parse() if *inputFile == "" { glog.Fatal("--input flag cannot be empty") } b, err := ioutil.ReadFile(*inputFile) if err != nil { glog.Fatal(err) } var userAgents []*userAgent err = json.Unmarshal(b, &userAgents) if err != nil { glog.Fatal(err) } var all, success int for _, client := range userAgents { all++ if testClient(client) { success++ } } glog.Infof("done %d/%d %.2f%%", success, all, (float64(success)/float64(all))*100.0) }
func main() { flag.Parse() trainData := &pb.TrainingData{} if err := parseToProto(*trainDataPath, trainData); err != nil { glog.Fatal(err) } glog.Infof( "Loaded %v training examples, %v test examples", len(trainData.GetTrain()), len(trainData.GetTest())) config := &pb.ForestConfig{} if err := parseToProto(*configPath, config); err != nil { glog.Fatal(err) } glog.Infof("Loaded forest config %+v", config) generator, err := dt.NewForestGenerator(config) if err != nil { glog.Fatal(err) } forest := generator.ConstructForest(trainData.GetTrain()) learningCurve := dt.LearningCurve(forest, trainData.GetTest()) glog.Infof("Learning curve: %+v", learningCurve) serializedForest, err := json.MarshalIndent(forest, "", " ") if err != nil { glog.Fatal(err) } os.Stdout.Write(serializedForest) }
func init() { flag.Parse() c, err := goconfig.ReadConfigFile("config") if err != nil { glog.Warningf("init(): readconfigfile(config)") oauthCfg.ClientSecret = "a" oauthCfg.ClientId = "b" MyURL = "c" oauthCfg.RedirectURL = "d" return } oauthCfg.ClientId, err = c.GetString("Google", "ClientId") if err != nil { glog.Fatal("init(): readconfigfile(Google.ClientId), using dummy") } oauthCfg.ClientSecret, err = c.GetString("Google", "ClientSecret") if err != nil { glog.Fatal("init(): readconfigfile(Google.ClientSecret)") } url, err := c.GetString("Web", "url") MyURL = url if err != nil { glog.Fatal("init(): readconfigfile(Web.url)") } oauthCfg.RedirectURL = url + "/oauth2callback" }
// InitDBConnection will establish the connection to the database or die trying func InitDBConnection(c DBConfig) { var err error db, err = sql.Open( "postgres", fmt.Sprintf( "user=%s dbname=%s host=%s port=%d password=%s sslmode=%s", c.Username, c.Database, c.Host, c.Port, c.Password, "disable", ), ) if err != nil { glog.Fatal(fmt.Sprintf("Database connection failed: %v", err.Error())) } err = db.Ping() if err != nil { glog.Fatal(err) } // PostgreSQL max is 100, we need to be below that limit as there may be // connections from monitoring apps, migrations in process or active // debugging by staff db.SetMaxOpenConns(90) // Any connections above this number that are in the pool and idle will be // returned to the database. We should keep this number low enough to help // recycle connections over time and to provide spare capacity when needed // whilst operating at a lower memory use. But we should keep it high // enough that we aren't constantly waiting for connections to be opened. // db.SetMaxIdleConns(50) }
func Fatal(ctx context.Context, args ...interface{}) { if ctx == nil || !hasTraceKey(ctx) { glog.Fatal(args) return } glog.Fatal(prependParam(args, ctx)...) }
func (server *Server) monitor(ctx *zmq.Context, addr string) { sock, err := ctx.NewSocket(zmq.PAIR) if err != nil { glog.Fatal(err) } if err := sock.Connect(addr); err != nil { glog.Fatal(err) } defer sock.Close() var lock sync.Mutex var numClients int for { evtType, _, _, err := sock.RecvEvent(0) if err != nil { glog.Error(err) break } switch zmq.Event(evtType) { case zmq.EVENT_ACCEPTED: lock.Lock() numClients++ glog.Infof("Client #%d connected", numClients) lock.Unlock() case zmq.EVENT_DISCONNECTED: lock.Lock() glog.Infof("Client #%d disconnected", numClients) numClients-- lock.Unlock() } } }
func run() { // Init API api := New(Address) api.Init() // Initialise Server service := micro.NewService( micro.Name("go.micro.api"), ) // Start API if err := api.Start(); err != nil { log.Fatal(err) } // Run server if err := service.Run(); err != nil { log.Fatal(err) } // Stop API if err := api.Stop(); err != nil { log.Fatal(err) } }
func main() { flag.Parse() defer glog.Flush() router := mux.NewRouter() router.HandleFunc("/", indexHandler).Methods("GET") router.HandleFunc("/debug", debugHandler).Methods("GET", "POST") router.HandleFunc("/query", queryHandler).Methods("GET", "POST") router.HandleFunc("/ingest", ingestHandler).Methods("POST") router.HandleFunc("/stats", statsHandler).Methods("GET") router.HandleFunc("/purge", purgeHandler).Methods("GET") loggingHandler := NewLoggingHandler(router) serverAddr := fmt.Sprintf(":%d", 8080) server := &http.Server{ Addr: serverAddr, Handler: loggingHandler, } if err := echoprint.DBConnect(); err != nil { glog.Fatal(err) } defer echoprint.DBDisconnect() // TODO: gracefully stop http server (github.com/tylerb/graceful etc) glog.Infof("Starting server [%s]", serverAddr) if err := server.ListenAndServe(); err != nil { glog.Fatal(err) } }
// serve starts serving the provided http.Handler using security settings derived from the MasterConfig func (c *MasterConfig) serve(handler http.Handler, extra []string) { timeout := c.Options.ServingInfo.RequestTimeoutSeconds if timeout == -1 { timeout = 0 } server := &http.Server{ Addr: c.Options.ServingInfo.BindAddress, Handler: handler, ReadTimeout: time.Duration(timeout) * time.Second, WriteTimeout: time.Duration(timeout) * time.Second, MaxHeaderBytes: 1 << 20, } go util.Forever(func() { for _, s := range extra { glog.Infof(s, c.Options.ServingInfo.BindAddress) } if c.TLS { server.TLSConfig = &tls.Config{ // Change default from SSLv3 to TLSv1.0 (because of POODLE vulnerability) MinVersion: tls.VersionTLS10, // Populate PeerCertificates in requests, but don't reject connections without certificates // This allows certificates to be validated by authenticators, while still allowing other auth types ClientAuth: tls.RequestClientCert, ClientCAs: c.ClientCAs, } glog.Fatal(cmdutil.ListenAndServeTLS(server, c.Options.ServingInfo.BindNetwork, c.Options.ServingInfo.ServerCert.CertFile, c.Options.ServingInfo.ServerCert.KeyFile)) } else { glog.Fatal(server.ListenAndServe()) } }, 0) }
func listSnapshots(c web.C, w http.ResponseWriter, r *http.Request) { db, err := sql.Open("sqlite3", "./database.db") if err != nil { log.Fatal("Failed to connect to database: %v\n", err) } defer db.Close() snapshotList := SnapshotList{} rows, err := db.Query("SELECT uri,storage_path FROM runs") if err != nil { log.Fatal(err) } defer rows.Close() for rows.Next() { var uri string var storage string rows.Scan(&uri, &storage) snap := Snapshot{ URI: uri, Path: fmt.Sprintf("https://s3.amazonaws.com/mesos-hackathon-bucket/%s", storage), } snapshotList.Snapshots = append(snapshotList.Snapshots, snap) } uriJson, err := json.MarshalIndent(snapshotList, "", " ") if err != nil { log.Fatal(err) } fmt.Fprintf(w, string(uriJson)) }