func main() { switch len(os.Args) { case 1: break case 2: err := os.Chdir(os.Args[1]) if err != nil { panic(err) } break default: return } err := config.Load("./data/data.db") if err != nil { panic(err) } allow, _ := strconv.ParseBool(config.Get("archive_migrate")) if allow != true { fmt.Println("Migrate not allowed in this environment") return } config.Dump(os.Stdout) m, err := getData() if err != nil { panic(err) } invoiceData := config.Get("invoice_data") fmt.Printf("=> %s\n", invoiceData) m.Invoice.Save(invoiceData) archivePath := config.Get("archive_path") err = os.RemoveAll(archivePath) if err != nil { panic(err) } err = os.MkdirAll(archivePath, 0755) if err != nil { panic(err) } for _, a := range m.Archive { err = saveFile(a.Url, filepath.Join(archivePath, a.Name)) if err != nil { fmt.Println(err.Error()) } } fmt.Println("OK") }
func main() { switch len(os.Args) { case 1: break case 2: err := os.Chdir(os.Args[1]) if err != nil { panic(err) } break default: return } err := config.Load("./data/data.db") if err != nil { panic(err) } config.Dump(os.Stdout) h, err := handler.New() if err != nil { panic(err) } err = ioutil.WriteFile("./pid", []byte(strconv.Itoa(os.Getpid())), 0644) if err != nil { panic(err) } http.Handle("/", h) err = http.ListenAndServe(config.Get("bind"), nil) if err != nil { panic(err) } }