func main() { var configPath string flag.StringVar(&configPath, "c", "config.json", "Path to config file") flag.Parse() flag.Visit(func(v *flag.Flag) { fmt.Printf("%s - %s: %s\n", v.Usage, v.Name, v.Value) }) config := rapi.NewConfigFile(configPath) api := rapi.New(config) api.NewEndpoint("GET", "/users") api.Run() }
func TestEndpoint(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) defer ts.Close() conf := rapi.NewConfig() conf.Backend.Address = strings.TrimPrefix(ts.URL, "http://") api := rapi.New(conf) require.NotNil(t, api) ep := rapi.NewEndpoint(api, "GET", "/foo") assert.NotNil(t, ep) req, err := http.NewRequest("GET", "/foo", nil) require.Nil(t, err) require.NotNil(t, req) resp := httptest.NewRecorder() require.NotNil(t, resp) ep.ServeHTTP(resp, req) }
func TestCreateApi(t *testing.T) { config := rapi.NewConfig() rapi.New(config) }