func TestNoDownloadUrl(t *testing.T) { app := NewConoHaIso() f := flag.NewFlagSet("test", 0) test := []string{"conoha-iso", "download"} f.Parse(test) err := app.Run(f.Args()) if err == nil { pp.Printf("err:%v\n", err) t.Errorf("No download url specified. Test should be fail in this case.") } }
func main() { // flags host := flag.String("h", "127.0.0.1", "host") port := flag.Int("p", 3000, "port") del := flag.Bool("del", false, "delete?") flag.Parse() // connect to Aerospike if h, found := os.LookupEnv("AEROSPIKE_PORT_3000_TCP_ADDR"); found { *host = h } cl, err := asc.NewClient(*host, *port) panicOnErr(err) key, err := asc.NewKey("test", "aerospike", "key") panicOnErr(err) // define some bins with data bins := asc.BinMap{ "bin1": 42, "bin2": "elephant", "bin3": []interface{}{"Go", 2009}, } // write the bins wp := asc.NewWritePolicy(0, 0) wp.SendKey = true // also send the key itself err = cl.Put(wp, key, bins) panicOnErr(err) rec, err := cl.Get(nil, key) panicOnErr(err) _, _ = pp.Printf("key: %v\nbins: %v\n", *rec.Key, rec.Bins) // scan all data rs, err := cl.ScanAll(nil, "test", "aerospike") panicOnErr(err) defer rs.Close() for r := range rs.Results() { _, _ = pp.Println(*r.Record.Key, r.Record.Bins) } if *del { existed, err := cl.Delete(nil, key) panicOnErr(err) fmt.Printf("Record existed before delete? %v\n", existed) } }
func TestNoRegion(t *testing.T) { app := NewConoHaIso() f := flag.NewFlagSet("test", 0) for _, command := range []string{"list", "download", "eject", "insert"} { test := []string{"conoha-iso", command} f.Parse(test) err := app.Run(f.Args()) if err == nil { pp.Printf("err:%v\n", err) t.Errorf("No region specified. Test should be fail in this case.") } } }
func main() { e := echo.New() e.Use(middleware.Logger()) e.Use(middleware.Recover()) e.GET("/", func(context echo.Context) error { return context.String(http.StatusOK, "Hello Blue") }) e.GET("/search/address", func(context echo.Context) error { postalcode := context.QueryParam("postalcode") var result = common.SearchAddress(postalcode) pp.Printf("SearchAddress result: %s", result) return context.JSON(http.StatusOK, result) }) e.GET("/customer", func(context echo.Context) error { var customers = customer.GetCustomer() return context.JSON(http.StatusOK, customers) }) e.POST("/customer/save", func(context echo.Context) error { c := new(customer.Customer) // リクエストをCustomerにバインドします。 if err := context.Bind(c); err != nil { return err } savedCustomer, err := customer.SaveCustomer(c) if err != nil { return err } return context.JSON(http.StatusOK, savedCustomer) }) e.POST("/customer/delete", func(context echo.Context) error { c := new(customer.Customer) if err := context.Bind(c); err != nil { return err } deletedCustomer, err := customer.DeleteCustomer(c) if err != nil { return err } return context.JSON(http.StatusOK, deletedCustomer) }) e.GET("/tax", func(context echo.Context) error { var taxResult = master.GetTax() return context.JSON(http.StatusOK, taxResult) }) e.POST("/tax/save", func(context echo.Context) error { t := new(master.Tax) // リクエストをTaxにバインドします。 if err := context.Bind(t); err != nil { return err } savedTax, err := master.SaveTax(t) if err != nil { return err } return context.JSON(http.StatusOK, savedTax) }) // CORS (Cross-Origin Resource Sharing)を許可します。 e.Use(middleware.CORSWithConfig(middleware.CORSConfig{ AllowOrigins: []string{"*"}, })) e.Run(standard.New(":1323")) }