func main() { flag.Parse() auth.AccessPassword = os.Getenv("CAMLI_PASSWORD") if len(auth.AccessPassword) == 0 { fmt.Fprintf(os.Stderr, "No CAMLI_PASSWORD environment variable set.\n") os.Exit(1) } { fi, err := os.Stat(*flagStorageRoot) if err != nil || !fi.IsDirectory() { fmt.Fprintf(os.Stderr, "Storage root '%s' doesn't exist or is not a directory.\n", *flagStorageRoot) os.Exit(1) } } blobFetcher = newDiskStorage(*flagStorageRoot) ws := webserver.New() ws.HandleFunc("/", handleRoot) ws.HandleFunc("/camli/", handleCamli) ws.Handle("/js/", http.FileServer("../../clients/js", "/js/")) ws.Serve() }
func main() { flag.Parse() auth.AccessPassword = os.Getenv("CAMLI_PASSWORD") if len(auth.AccessPassword) == 0 { fmt.Fprintf(os.Stderr, "No CAMLI_PASSWORD environment variable set.\n") os.Exit(1) } ws := webserver.New() ws.HandleFunc("/", handleRoot) ws.HandleFunc("/camli/sig/", handleCamliSig) ws.Serve() }
func main() { flag.Parse() file := *flagConfigFile if !filepath.IsAbs(file) { file = filepath.Join(osutil.CamliConfigDir(), file) } config, err := serverconfig.Load(file) if err != nil { exitFailure("Could not load server config: %v", err) } ws := webserver.New() baseURL := ws.BaseURL() { cert, key := config.OptionalString("TLSCertFile", ""), config.OptionalString("TLSKeyFile", "") if (cert != "") != (key != "") { exitFailure("TLSCertFile and TLSKeyFile must both be either present or absent") } if cert != "" { ws.SetTLS(cert, key) } } err = config.InstallHandlers(ws, baseURL) if err != nil { exitFailure("Error parsing config: %v", err) } ws.Listen() if config.UIPath != "" { uiURL := ws.BaseURL() + config.UIPath log.Printf("UI available at %s", uiURL) if runtime.GOOS == "windows" { // Might be double-clicking an icon with no shell window? // Just open the URL for them. osutil.OpenURL(uiURL) } } ws.Serve() }
func main() { flag.Parse() configPath := *flagConfigFile if !filepath.IsAbs(configPath) { configPath = filepath.Join(osutil.CamliConfigDir(), configPath) } f, err := os.Open(configPath) if err != nil { exitFailure("error opening %s: %v", configPath, err) } defer f.Close() dj := json.NewDecoder(f) rootjson := make(map[string]interface{}) if err = dj.Decode(&rootjson); err != nil { extra := "" if serr, ok := err.(*json.SyntaxError); ok { if _, serr := f.Seek(0, os.SEEK_SET); serr != nil { log.Fatalf("seek error: %v", serr) } line, col, highlight := errorutil.HighlightBytePosition(f, serr.Offset) extra = fmt.Sprintf(":\nError at line %d, column %d (file offset %d):\n%s", line, col, serr.Offset, highlight) } exitFailure("error parsing JSON object in config file %s%s\n%v", osutil.UserServerConfigPath(), extra, err) } if err := jsonconfig.EvaluateExpressions(rootjson); err != nil { exitFailure("error expanding JSON config expressions in %s: %v", configPath, err) } ws := webserver.New() baseURL := ws.BaseURL() // Root configuration config := jsonconfig.Obj(rootjson) { cert, key := config.OptionalString("TLSCertFile", ""), config.OptionalString("TLSKeyFile", "") if (cert != "") != (key != "") { exitFailure("TLSCertFile and TLSKeyFile must both be either present or absent") } if cert != "" { ws.SetTLS(cert, key) } } auth.AccessPassword = config.OptionalString("password", "") if url := config.OptionalString("baseURL", ""); url != "" { baseURL = url } prefixes := config.RequiredObject("prefixes") if err := config.Validate(); err != nil { exitFailure("configuration error in root object's keys in %s: %v", configPath, err) } hl := &handlerLoader{ ws: ws, baseURL: baseURL, config: make(map[string]*handlerConfig), handler: make(map[string]interface{}), } for prefix, vei := range prefixes { if !strings.HasPrefix(prefix, "/") { exitFailure("prefix %q doesn't start with /", prefix) } if !strings.HasSuffix(prefix, "/") { exitFailure("prefix %q doesn't end with /", prefix) } pmap, ok := vei.(map[string]interface{}) if !ok { exitFailure("prefix %q value isn't an object", prefix) } pconf := jsonconfig.Obj(pmap) handlerType := pconf.RequiredString("handler") handlerArgs := pconf.OptionalObject("handlerArgs") if err := pconf.Validate(); err != nil { exitFailure("configuration error in prefix %s: %v", prefix, err) } h := &handlerConfig{ prefix: prefix, htype: handlerType, conf: handlerArgs, } hl.config[prefix] = h } hl.setupAll() ws.Serve() }