• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang rest.Post函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ant0ine/go-json-rest/rest.Post函数的典型用法代码示例。如果您正苦于以下问题:Golang Post函数的具体用法?Golang Post怎么用?Golang Post使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Post函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: MsgServerStart

func MsgServerStart() {

	mqmsg := msgqueue.MqMsg{
		Msg: message.NewMsg(),
	}
	persistent := PerMqAgent{
		Msg: message.NewMsg(),
	}

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)

	router, err := rest.MakeRouter(
		//rest.Get("/test", msg.TestMsg),
		rest.Get("/testmq/:mqid", msgqueue.DefaultMM.TestMq),
		rest.Post("/send_msg/:mqid", mqmsg.PostMsg),
		rest.Get("/receive_msg/:mqid", mqmsg.GetMsg),
		rest.Post("/send/:mqid", persistent.PostMsg),
		rest.Get("/receive/:mqid", persistent.GetMsg),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe(":"+ListenPort, api.MakeHandler()))
}
开发者ID:jmptrader,项目名称:Caesar,代码行数:26,代码来源:msgServer.go


示例2: main

func main() {
	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)

	router, err := rest.MakeRouter(
		rest.Get("/test", testApi),
		rest.Post("/addTask", plain.AddTask),
		rest.Get("/getTasks", plain.GetTasks),
		rest.Post("/removeTask", plain.RemoveTask),
		rest.Post("/completeTask", plain.CloseTask),
		rest.Post("/rearrangeTasks", plain.RearrangeTasks),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)

	http.Handle("/api/", http.StripPrefix("/api", api.MakeHandler()))
	http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("frontend"))))

	log.Println("Listening...")

	http.ListenAndServe(":3000", nil)

}
开发者ID:trukhinyuri,项目名称:done,代码行数:25,代码来源:done.go


示例3: MakeHandler

// MakeHandler creates the api request handler
func MakeHandler() *http.Handler {
	api := rest.NewApi()

	authMiddleware, err := CreateAuthMiddleware()
	if err != nil {
		panic(err)
	}

	api.Use(&rest.IfMiddleware{
		// Only authenticate non login or register requests
		Condition: func(request *rest.Request) bool {
			return (request.URL.Path != variables.APIPathLoginUserServer) && (request.URL.Path != variables.APIPathRegisterUserServer)
		},
		IfTrue: authMiddleware,
	})
	api.Use(rest.DefaultProdStack...)
	router, err := rest.MakeRouter(
		rest.Post(variables.APIPathLoginUserServer, authMiddleware.LoginHandler),
		rest.Get(variables.APIPathRefreshUserServer, authMiddleware.RefreshHandler),
		rest.Post(variables.APIPathRegisterUserServer, PostRegister),
		rest.Get(variables.APIPathUserServer, GetUser),
		rest.Post(variables.APIPathUserServer, PostUser),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	handler := api.MakeHandler()
	return &handler
}
开发者ID:pdxjohnny,项目名称:numapp,代码行数:31,代码来源:handler.go


示例4: NewRest

// NewRest configures REST api handlers and wrappers.
func NewRest() *rest.Api {
	api := rest.NewApi()
	api.MakeHandler()
	api.Use(rest.DefaultDevStack...)

	api.Use(&rest.CorsMiddleware{
		RejectNonCorsRequests: false,
		OriginValidator: func(origin string, request *rest.Request) bool {
			return true
		},
		AllowedMethods: []string{"GET", "POST"},
		AllowedHeaders: []string{
			"Accept", "Content-Type", "X-Custom-Header", "Origin"},
		AccessControlAllowCredentials: true,
		AccessControlMaxAge:           3600,
	})

	router, err := rest.MakeRouter(
		rest.Post("/translations", translations),
		rest.Post("/suggestions", suggestions),
		rest.Get("/health", health),
	)
	if err != nil {
		log.Fatal(err)
	}

	api.SetApp(router)
	return api
}
开发者ID:eicca,项目名称:smart-translate-server,代码行数:30,代码来源:rest.go


示例5: initRoutes

func initRoutes(restApi *rest.Api) {
	authController := &AuthController{}
	appController := &ApplicationController{}
	typesController := &TypesController{}

	router, err := rest.MakeRouter(
		rest.Put(authController.Path(), authController.RegisterUserHandler),
		rest.Post(authController.Path(), authController.LoginUserHandler),
		rest.Put("/:appId"+authController.Path(), authController.AppRegisterUserHandler),
		rest.Post("/:appId"+authController.Path(), authController.AppLoginUserHandler),

		rest.Post(appController.Path(), appController.CreateApplicationHandler),
		rest.Get(appController.Path(), appController.GetApplicationsHandler),
		rest.Get(appController.Path()+"/:appId", appController.GetApplicationHandler),
		rest.Delete(appController.Path()+"/:appId", appController.DeleteApplicationHandler),
		rest.Put(appController.Path()+"/:appId", appController.UpdateApplicationHandler),

		rest.Post("/:appId"+typesController.Path(), typesController.CreateTypeHandler),
		rest.Delete("/:appId"+typesController.Path()+"/:typeName", typesController.DeleteType),
		rest.Post("/:appId"+typesController.Path()+"/:typeName", typesController.InsertInTypeHandler),
		rest.Get("/:appId"+typesController.Path()+"/:typeName", typesController.GetTypeDataHandler),
		rest.Get("/:appId"+typesController.Path()+"/:typeName/:itemId", typesController.GetTypeItemById),
		rest.Put("/:appId"+typesController.Path()+"/:typeName/:itemId", typesController.UpdateTypeItemById),
		rest.Delete("/:appId"+typesController.Path()+"/:typeName/:itemId", typesController.DeleteTypeItemById),
	)

	if err != nil {
		log.Fatal(err)
	}

	restApi.SetApp(router)
}
开发者ID:gitter-badger,项目名称:neutrino-core,代码行数:32,代码来源:api.go


示例6: main

func main() {
	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	//配置API跨域CORS
	api.Use(&rest.CorsMiddleware{
		RejectNonCorsRequests: false,
		OriginValidator: func(origin string, req *rest.Request) bool {
			return origin == req.Header.Get("Origin")
		},
		AllowedMethods: []string{"GET", "POST", "PUT"},
		AllowedHeaders: []string{
			"Accept", "Content-Type", "X-Custom-Header", "Origin"},
		AccessControlAllowCredentials: true,
		AccessControlMaxAge:           3600,
	})

	//设置API基本Router
	router, err := rest.MakeRouter(
		rest.Post("/:raw.json", RawWrite),
		rest.Post("/auth/login/:id", AuthLogin),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe(":8080", api.MakeHandler()))
}
开发者ID:ryanemax,项目名称:learngo,代码行数:27,代码来源:rest-main.go


示例7: Start

// Start start the http rest api plugin
func (cli *HTTPAPIServer) Start(config map[string]interface{}) error {

	wwwroot, _ := utils.GetString("static", config, "")
	addr, _ := utils.GetString("listen", config, ":8080")
	secret, ok := utils.GetString("secret", config, randomString(128))
	if !ok {
		logrus.Warnf("Plugins: httpapi: generated new secret: %s", secret)
	}

	jwt_middleware := &jwt.JWTMiddleware{
		Key:        []byte(secret),
		Realm:      "jwt auth",
		Timeout:    time.Hour,
		MaxRefresh: time.Hour * 24,
		Authenticator: func(userId string, password string) bool {
			return userId == "admin" && password == "admin"
		}}

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	api.Use(&rest.IfMiddleware{
		Condition: func(request *rest.Request) bool {
			return request.URL.Path != "/login"
		},
		IfTrue: jwt_middleware,
	})

	router, err := rest.MakeRouter(
		rest.Post("/login", jwt_middleware.LoginHandler),
		rest.Get("/refresh_token", jwt_middleware.RefreshHandler),

		rest.Get("/", getApiVersion),
		rest.Get("/sensors", getAllSensors),
		rest.Get("/sensors/:backend.:sensor", getSensor),
		rest.Get("/services", getAllServices),
		rest.Get("/services/:backend.:service", getService),
		rest.Post("/services/:backend.:service", callService),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)

	http.Handle("/v1/", http.StripPrefix("/v1", api.MakeHandler()))

	if wwwroot != "" {
		logrus.Infof("Plugin: httpapi: service static content from %s", wwwroot)
		http.Handle("/ui/", http.StripPrefix("/ui", http.FileServer(http.Dir(wwwroot))))
	}

	go func() {
		logrus.Infof("Plugin: httpapi: starting on %s", addr)
		manners.ListenAndServe(addr, http.DefaultServeMux)
	}()

	return nil
}
开发者ID:nethack42,项目名称:go-home,代码行数:58,代码来源:httpapi.go


示例8: main

func main() {
	var err error

	api := rest.NewApi()

	// Enable basic middlewares.
	api.Use(rest.DefaultDevStack...)
	// Enable CORS middleware.
	api.Use(&rest.CorsMiddleware{
		RejectNonCorsRequests: false,
		OriginValidator: func(origin string, request *rest.Request) bool {
			return true
		},
		AllowedMethods: []string{"GET", "POST", "PUT", "DELETE"},
		AllowedHeaders: []string{
			"Accept", "Content-Type", "X-Custom-Header", "Origin"},
		AccessControlAllowCredentials: true,
		AccessControlMaxAge:           3600,
	})
	// Enable token validation middleware.
	api.Use(&mw.AuthMW{})

	router, err := rest.MakeRouter(
		// cards.
		rest.Get("/cards", GetUserCards),
		rest.Get("/cards/:cid", GetCard),
		rest.Post("/cards", CreateCard),
		rest.Put("/cards/:cid", UpdateCard),
		rest.Delete("/cards/:cid", DeleteCard),

		rest.Get("/challenge", GetChallenge),
		rest.Post("/results", SaveResult),

		// user endpoints.
		rest.Get("/users/:uid", GetUser),
		rest.Put("/users/:uid", UpdateUser),
		rest.Delete("/users/:uid", DeleteUser),

		// token
		rest.Post("/token", GetToken),

		// ping
		rest.Get("/ping", Ping),
	)

	if err != nil {
		log.Fatal(err)
	}

	api.SetApp(router)
	log.Fatal(http.ListenAndServe(":8080", api.MakeHandler()))
}
开发者ID:hairqles,项目名称:scholar,代码行数:52,代码来源:main.go


示例9: main

func main() {

	DataFile, err := os.Open(configFile)
	if err != nil {
		log.Fatal("Error opening Config file", err.Error())
		os.Exit(2)
	}

	jsonParser := json.NewDecoder(DataFile)

	if err = jsonParser.Decode(&serverData); err != nil {
		log.Fatal("Error parsing config file", err.Error())
		os.Exit(2)
	}
	Println(timeNow, " --- Config file ", configFile, " loaded")
	Println(timeNow, " --- Starting web server listener on host:", serverData.Host, "on port:", serverData.Port)

	jwt_middleware := &jwt.JWTMiddleware{
		Key:        []byte("secret key"),
		Realm:      "jwt auth",
		Timeout:    time.Hour,
		MaxRefresh: time.Hour * 24,
		Authenticator: func(userId string, password string) bool {
			return userId == "admin" && password == "admin"
		}}

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	// we use the IfMiddleware to remove certain paths from needing authentication
	api.Use(&rest.IfMiddleware{
		Condition: func(request *rest.Request) bool {
			return request.URL.Path != "/login"
		},
		IfTrue: jwt_middleware,
	})

	api_router, _ := rest.MakeRouter(
		rest.Post("/login", jwt_middleware.LoginHandler),
		rest.Get("/auth_test", handle_auth),
		rest.Get("/refresh_token", jwt_middleware.RefreshHandler),
		rest.Get("/index", Index),
		rest.Get("/messages", GetAllMessages),
		rest.Post("/messages", PostMessage),
		rest.Get("/countries/:code", GetMessage),
		//		rest.Delete("/countries/:code", DeleteMessage),
	)
	api.SetApp(api_router)

	http.Handle("/api/", http.StripPrefix("/api", api.MakeHandler()))

	log.Fatal(http.ListenAndServe(serverData.Host+":"+serverData.Port, nil))
}
开发者ID:Chubik,项目名称:shaurma,代码行数:52,代码来源:shaurma.go


示例10: Serve

// Serve a json api
func Serve() {

	redisPool = newPool(redisServer, redisPassword)

	api := rest.NewApi()

	api.Use(&rest.IfMiddleware{
		Condition: func(request *rest.Request) bool {
			return request.URL.Path != "/login"
		},
		IfTrue: &tokenauth.AuthTokenMiddleware{
			Realm: authRealm,
			Authenticator: func(token string) string {
				rd := redisPool.Get()
				defer rd.Close()
				user, _ := redis.String(rd.Do("GET", tokenNamespace+tokenauth.Hash(token)))
				return user
			},
		},
		IfFalse: &rest.AuthBasicMiddleware{
			Realm: authRealm,
			Authenticator: func(user string, password string) bool {
				if user == "user" && password == "password" {
					return true
				}
				return false
			},
		},
	})

	api.Use(rest.DefaultDevStack...)
	router, err := rest.MakeRouter(
		rest.Post("/login", login),
		rest.Get("/containers", list),
		rest.Get("/container/:id", inspect),
		rest.Post("/image/build", build),
		rest.Post("/image/run", create),
		rest.Get("/container/start/:id", start),
		rest.Get("/container/stop/:id", stop),
	)

	if err != nil {
		log.Fatal(err)
	}

	api.SetApp(router)
	log.Println("Port", port)
	log.Fatal(http.ListenAndServe(":"+port, api.MakeHandler()))
}
开发者ID:ds0nt,项目名称:klouds-agent,代码行数:50,代码来源:api.go


示例11: RunApiServer

func (fx_api *FxDaemonApi) RunApiServer() {
	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	router, err := rest.MakeRouter(
		rest.Post("/childs", fx_api.ChildServers),
		rest.Post("/child/iplookup", fx_api.ChildServerIpLookup),

		rest.Post("/transfer/container", fx_api.TransferContainer),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe(fx_api.Fxd.ListenHost, api.MakeHandler()))
}
开发者ID:smw,项目名称:flaxton,代码行数:15,代码来源:daemonApi.go


示例12: main

func main() {
	// context
	ctx = context.Background()

	// db
	hoge.BuildInstances()

	// redis
	redis_pool := newPool()
	ctx = context.WithValue(ctx, "redis", redis_pool)

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	router, err := rest.MakeRouter(
		rest.Post("/test", baseHandlerFunc(controller.Test)),
	)

	// 存在しないルート時
	if err != nil {
		log.Fatal(err)
	}

	api.SetApp(router)
	httpErr := http.ListenAndServe(":9999", api.MakeHandler())
	if httpErr != nil {
		log.Fatal(err, "http error!!")
	}
}
开发者ID:shamoto-donuts,项目名称:goSample,代码行数:28,代码来源:main.go


示例13: main

func main() {
	// context
	ctx = context.Background()
	db := initDb()
	ctx = context.WithValue(ctx, "test", "aaabbbccc")
	ctx = context.WithValue(ctx, "DB", db)

	// redis
	redis_pool := newPool()
	ctx = context.WithValue(ctx, "redis", redis_pool)

	str := ctx.Value("test")
	log.Println(str)

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	router, err := rest.MakeRouter(
		rest.Post("/test", baseHandlerFunc(controller.Test)),
	)

	// 存在しないルート時
	if err != nil {
		log.Fatal(err)
	}

	api.SetApp(router)
	log.Fatal(http.ListenAndServe(":9999", api.MakeHandler()))
}
开发者ID:shamoto-donuts,项目名称:goSample,代码行数:28,代码来源:main.go


示例14: main

func main() {
	jwt_middleware := &jwt.JWTMiddleware{
		Key:        []byte("secret key"),
		Realm:      "jwt auth",
		Timeout:    time.Hour,
		MaxRefresh: time.Hour * 24,
		Authenticator: func(userId string, password string) bool {
			return userId == "admin" && password == "admin"
		}}

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	// we use the IfMiddleware to remove certain paths from needing authentication
	api.Use(&rest.IfMiddleware{
		Condition: func(request *rest.Request) bool {
			return request.URL.Path != "/login"
		},
		IfTrue: jwt_middleware,
	})
	api_router, _ := rest.MakeRouter(
		rest.Post("/login", jwt_middleware.LoginHandler),
		rest.Get("/auth_test", handle_auth),
		rest.Get("/refresh_token", jwt_middleware.RefreshHandler),
	)
	api.SetApp(api_router)

	http.Handle("/api/", http.StripPrefix("/api", api.MakeHandler()))

	log.Fatal(http.ListenAndServe(":8080", nil))
}
开发者ID:jemkzheng,项目名称:go-json-rest-examples,代码行数:30,代码来源:main.go


示例15: StartServer

func (app *App) StartServer(addr string, dbFileName string) {
	err := app.InitDB(dbFileName)
	if err != nil {
		log.Fatal(err)
	}
	api := rest.NewApi()
	api.Use(rest.DefaultProdStack...)
	api.Use(&rest.CorsMiddleware{
		RejectNonCorsRequests: false,
		AllowedMethods:        []string{"GET", "POST"},
		AllowedHeaders: []string{
			"Accept", "Content-Type", "Origin"},
		AccessControlAllowCredentials: true,
		AccessControlMaxAge:           2592000,

		OriginValidator: func(origin string, request *rest.Request) bool {
			return true
		},
	})
	router, err := rest.MakeRouter(
		rest.Get("/latest", app.GetLatest),
		rest.Get("/last", app.GetLast),
		rest.Get("/all", app.GetAll),
		rest.Post("/postEntry", app.PostEntry),
		//rest.Post("/postSignedEntry", app.PostJwtEntry),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe(addr, api.MakeHandler()))
}
开发者ID:ubergesundheit,项目名称:simple-time-series-server,代码行数:32,代码来源:simple-time-series-server.go


示例16: main

func main() {
	i := Impl{}
	i.InitDB()
	i.InitSchema()

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	api.Use(&rest.CorsMiddleware{
		RejectNonCorsRequests: false,
		OriginValidator: func(origin string, request *rest.Request) bool {
			return true
		},
		AllowedMethods: []string{"GET", "POST", "PUT"},
		AllowedHeaders: []string{
			"Accept", "Content-Type", "X-Custom-Header", "Origin"},
		AccessControlAllowCredentials: true,
		AccessControlMaxAge:           3600,
	})
	router, err := rest.MakeRouter(
		rest.Get("/services", i.GetAllServices),
		rest.Post("/services", i.PostService),
		rest.Get("/services/:id", i.GetService),
		rest.Put("/services/:id", i.PutService),
		rest.Delete("/services/:id", i.DeleteService),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe(":8080", api.MakeHandler()))
}
开发者ID:mrcsparker,项目名称:translator-training,代码行数:31,代码来源:main.go


示例17: main

func main() {
	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)

	/*
		api.Use(&rest.CorsMiddleware{
			RejectNonCorsRequests: false,
			OriginValidator: func(origin string, request *rest.Request) bool {
				return true
			},
			AllowedMethods: []string{"GET", "POST", "PUT"},
			AllowedHeaders: []string{
				"Accept", "Content-Type", "X-Custom-Header", "Origin"},
			AccessControlAllowCredentials: true,
			AccessControlMaxAge:           3600,
		})
	*/
	router, err := rest.MakeRouter(
		rest.Post("/test", test),
	)

	// 存在しないルート時
	if err != nil {
		log.Fatal(err)
	}

	api.SetApp(router)
	log.Fatal(http.ListenAndServe(":9999", api.MakeHandler()))
}
开发者ID:shamoto-donuts,项目名称:goSample,代码行数:29,代码来源:main.go


示例18: MakeHandler

// MakeHandler creates the api request handler
func MakeHandler() *http.Handler {
	api := rest.NewApi()

	// Create the geospcail index on the data
	// FIXME: The collection is currently specified by the client
	collection := "thing"
	_, err := dbAPI.Index(variables.ServiceDBURL, token.BackendToken, collection, "location", "2dsphere")
	if err != nil {
		log.Println("ERROR setting index:", err)
	}

	// Make sure we want to enable auth
	if variables.EnableAuth != false {
		authMiddleware, err := CreateAuthMiddleware()
		if err != nil {
			log.Fatal(err)
		}

		api.Use(&rest.IfMiddleware{
			// Only authenticate non login or register requests
			Condition: func(request *rest.Request) bool {
				return true
			},
			IfTrue: authMiddleware,
		})
	}
	api.Use(rest.DefaultProdStack...)
	router, err := rest.MakeRouter(
		// For checking what is near a location
		rest.Post(dbVariables.APIPathNearServer, PostNear),
		// For geting and saving things
		rest.Get(dbVariables.APIPathGetServer, GetDoc),
		rest.Post(dbVariables.APIPathSaveServer, PostSaveDoc),
		// // For user actions such as login
		// rest.Post(variables.APIPathLoginUserServer, PostLoginUser),
		// rest.Get(variables.APIPathRefreshUserServer, PostRefreshUser),
		// rest.Post(variables.APIPathRegisterUserServer, PostRegisterUser),
		// rest.Get(variables.APIPathUserServer, GetUser),
		// rest.Post(variables.APIPathUserServer, PostUser),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	handler := api.MakeHandler()
	return &handler
}
开发者ID:pdxjohnny,项目名称:eco,代码行数:48,代码来源:handler.go


示例19: serveREST

func (r *Controller) serveREST(conf *goconf.ConfigFile) {
	c, err := parseRESTConfig(conf)
	if err != nil {
		r.log.Err(fmt.Sprintf("Controller: parsing REST configurations: %v", err))
		return
	}

	api := rest.NewApi()
	router, err := rest.MakeRouter(
		rest.Get("/api/v1/switch", r.listSwitch),
		rest.Post("/api/v1/switch", r.addSwitch),
		rest.Delete("/api/v1/switch/:id", r.removeSwitch),
		rest.Options("/api/v1/switch/:id", r.allowOrigin),
		rest.Get("/api/v1/port/:switchID", r.listPort),
		rest.Get("/api/v1/network", r.listNetwork),
		rest.Post("/api/v1/network", r.addNetwork),
		rest.Delete("/api/v1/network/:id", r.removeNetwork),
		rest.Options("/api/v1/network/:id", r.allowOrigin),
		rest.Get("/api/v1/ip/:networkID", r.listIP),
		rest.Get("/api/v1/host", r.listHost),
		rest.Post("/api/v1/host", r.addHost),
		rest.Delete("/api/v1/host/:id", r.removeHost),
		rest.Options("/api/v1/host/:id", r.allowOrigin),
		rest.Get("/api/v1/vip", r.listVIP),
		rest.Post("/api/v1/vip", r.addVIP),
		rest.Delete("/api/v1/vip/:id", r.removeVIP),
		rest.Options("/api/v1/vip/:id", r.allowOrigin),
		rest.Put("/api/v1/vip/:id", r.toggleVIP),
	)
	if err != nil {
		r.log.Err(fmt.Sprintf("Controller: making a REST router: %v", err))
		return
	}
	api.SetApp(router)

	addr := fmt.Sprintf(":%v", c.port)
	if c.tls.enable {
		err = http.ListenAndServeTLS(addr, c.tls.certFile, c.tls.keyFile, api.MakeHandler())
	} else {
		err = http.ListenAndServe(addr, api.MakeHandler())
	}

	if err != nil {
		r.log.Err(fmt.Sprintf("Controller: listening on HTTP: %v", err))
		return
	}
}
开发者ID:yebinMoon,项目名称:cherry,代码行数:47,代码来源:controller.go


示例20: main

func main() {

	api := rest.NewApi()

	statusMw := &rest.StatusMiddleware{}
	api.Use(statusMw)

	api.Use(&rest.GzipMiddleware{})
	api.Use(&rest.AccessLogJsonMiddleware{})

	api.Use(rest.DefaultDevStack...)
	router, err := rest.MakeRouter(
		//used for service status reporting
		rest.Get("/data/.status", func(w rest.ResponseWriter, r *rest.Request) {
			w.WriteJson(statusMw.GetStatus())
		}),

		rest.Post("/login", login),
		rest.Post("/refresh", refresh),
		rest.Post("/signup", signup),

		rest.Get("/data/:userid/smbgs", func(w rest.ResponseWriter, r *rest.Request) {
			checkAuth(w, r, getSmbgs)
		}),
		rest.Post("/data/:userid/smbgs", func(w rest.ResponseWriter, r *rest.Request) {
			checkAuth(w, r, postSmbgs)
		}),
		rest.Put("/data/:userid/smbgs", notImplemented),

		rest.Get("/data/:userid/notes", func(w rest.ResponseWriter, r *rest.Request) {
			checkAuth(w, r, getNotes)
		}),
		rest.Post("/data/:userid/notes", func(w rest.ResponseWriter, r *rest.Request) {
			checkAuth(w, r, postNotes)
		}),
		rest.Put("/data/:userid/notes", notImplemented),

		rest.Get("/data/:userid/basals", notImplemented),
		rest.Post("/data/:userid/basals", notImplemented),
		rest.Put("/data/:userid/basals", notImplemented),

		rest.Get("/data/:userid/boluses", notImplemented),
		rest.Post("/data/:userid/boluses", notImplemented),
		rest.Put("/data/:userid/boluses", notImplemented),

		rest.Get("/data/:userid/cbgs", notImplemented),
		rest.Post("/data/:userid/cbgs", notImplemented),
		rest.Put("/data/:userid/cbgs", notImplemented),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Println(http.ListenAndServe(":8090", api.MakeHandler()))
}
开发者ID:jh-bate,项目名称:fantail,代码行数:55,代码来源:restApi.go



注:本文中的github.com/ant0ine/go-json-rest/rest.Post函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang rest.Put函数代码示例发布时间:2022-05-24
下一篇:
Golang rest.NotFound函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap