func main() { fOne, err := zrsc.Open("one.txt") catch(err) _, err = io.Copy(os.Stdout, fOne) catch(err) fTwo, err := zrsc.Open("two.txt") catch(err) _, err = io.Copy(os.Stdout, fTwo) catch(err) }
func ServeAsset(w http.ResponseWriter, r *http.Request) { name := path.Join("ui", "assets", r.URL.Path) f, err := zrsc.Open(name) if os.IsNotExist(err) { http.ServeFile(w, r, name) return } catch(err) defer f.Close() fi, err := f.Stat() catch(err) modSince, err := time.Parse(http.TimeFormat, r.Header.Get("If-Modified-Since")) if err == nil && fi.ModTime().Before(modSince.Add(1*time.Second)) { w.Header().Set("Cache-Control", "public") http.Error(w, "", http.StatusNotModified) return } w.Header().Set("Content-Type", mime.TypeByExtension(path.Ext(fi.Name()))) w.Header().Set("Cache-Control", "public") w.Header().Set("Last-Modified", fi.ModTime().UTC().Format(http.TimeFormat)) _, err = io.Copy(w, f) catch(err) }
func init() { f, err := zrsc.Open("ui/index.min.html") catch(err) b, err := ioutil.ReadAll(f) catch(err) _, err = tplIndex.Parse(string(b)) catch(err) err = f.Close() catch(err) }
func init() { db = func() *sql.DB { db, err := sql.Open("sqlite3", "cactus.db") catch(err) return db }() v := 0 err := db.QueryRow("PRAGMA user_version"). Scan(&v) if v > 0 && v < 1 { log.Fatal("incompatible database; exiting") } if v == 0 { _, err = db.Exec("PRAGMA user_version = 1") catch(err) } f, err := zrsc.Open(path.Join("data", "db-init.sql")) catch(err) b, err := ioutil.ReadAll(f) catch(err) _, err = db.Exec(string(b)) catch(err) err = f.Close() catch(err) cnt, err := GetContest() catch(err) if !cnt.Ready { cnt.Title = "Untitled" cnt.Starts = time.Now().Add(1 * time.Hour) cnt.Length = 120 cnt.Ready = true cnt.Created = time.Now() err = cnt.Put() catch(err) } acc, err := GetAccount(1) catch(err) if acc == nil { acc = &Account{ Handle: "cactus", Level: Administrator, Name: "Cactus", } err = acc.SetPassword("cactus") catch(err) err = acc.Put() catch(err) } }
func main() { runtime.GOMAXPROCS((runtime.NumCPU() + 1) / 2) _, err := os.Stat("config.tml") if os.IsNotExist(err) { f2, err := zrsc.Open("cmd/cactus/config-sample.tml") catch(err) f, err := os.Create("config.tml") _, err = io.Copy(f, f2) catch(err) err = f2.Close() catch(err) err = f.Close() catch(err) } cfg, err = toml.LoadFile("config.tml") catch(err) go func() { addr, ok := cfg.Get("core.addr").(string) if !ok { log.Fatal("Missing core.addr in config.tml") } log.Printf("Listening on %s", addr) err := http.ListenAndServe(addr, nil) catch(err) }() beltSize, ok := cfg.Get("belt.size").(int64) if !ok { log.Fatal("Missing belt.size in config.tml") } for ; beltSize > 0; beltSize-- { go belt.Loop() } sigCh := make(chan os.Signal) signal.Notify(sigCh, os.Interrupt) log.Printf("Received %s; exiting", <-sigCh) }
func init() { _, err := os.Stat("config.tml") if os.IsNotExist(err) { f2, err := zrsc.Open("config-sample.tml") catch(err) f, err := os.Create("config.tml") _, err = io.Copy(f, f2) catch(err) err = f2.Close() catch(err) err = f.Close() catch(err) } cfg, err = toml.LoadFile("config.tml") catch(err) }