当前位置: 首页>>代码示例>>Golang>>正文


Golang rest.Put函数代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: getRouter

func getRouter() (rest.App, error) {
	mcPlugins := routes.McPlugins{}

	router, err := rest.MakeRouter(
		rest.Get("/plugins", mcPlugins.GetAllPlugins),
		rest.Post("/plugins", mcPlugins.PostPlugin),
		rest.Get("/plugins/:id", mcPlugins.GetPlugin),
		rest.Put("/plugins/:id", mcPlugins.PutPlugin),
		rest.Delete("/plugins/:id", mcPlugins.DeletePlugin),
	)
	return router, err
}
开发者ID:AndyEverLie,项目名称:mc_api,代码行数:12,代码来源:main.go

示例6: RunServer

func (fe *Frontend) RunServer(blocking bool) http.Handler {
	api := rest.NewApi()
	api.Use(&rest.AuthBasicMiddleware{
		Realm: "test zone",
		Authenticator: func(userId string, password string) bool {
			if userId == fe.cfg.Network.Username &&
				password == fe.cfg.Network.Password {
				return true
			}
			return false
		},
	})
	api.Use(rest.DefaultDevStack...)
	router, err := rest.MakeRouter(
		rest.Get("/subnets", fe.GetAllSubnets),
		rest.Get("/subnets/#id", fe.GetSubnet),
		rest.Post("/subnets", fe.CreateSubnet),
		rest.Put("/subnets/#id", fe.UpdateSubnet),
		rest.Delete("/subnets/#id", fe.DeleteSubnet),
		rest.Post("/subnets/#id/bind", fe.BindSubnet),
		rest.Delete("/subnets/#id/bind/#mac", fe.UnbindSubnet),
		rest.Put("/subnets/#id/next_server/#ip", fe.NextServer),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)

	connStr := fmt.Sprintf(":%d", fe.cfg.Network.Port)
	log.Println("Web Interface Using", connStr)
	if blocking {
		if fe.cert_pem == "" || fe.key_pem == "" {
			log.Fatal(http.ListenAndServe(connStr, api.MakeHandler()))
		} else {
			log.Fatal(http.ListenAndServeTLS(connStr, fe.cert_pem, fe.key_pem, api.MakeHandler()))
		}
	}
	return api.MakeHandler()
}
开发者ID:galthaus,项目名称:ocb-dhcp,代码行数:39,代码来源:api.go

示例7: MakeHandler

func (r *restServerAPI) MakeHandler() (http.Handler, error) {
	router, err := grest.MakeRouter(
		// Auth
		grest.Post("/login", r.Login),
		// Users
		grest.Get("/me", r.Me),
		grest.Get("/users", r.ListUsers),
		grest.Get("/users/#email", r.GetUser),
		grest.Post("/users/#email", r.CreateUser),
		grest.Put("/users/#email", r.UpdateUser),
		// Groups
		grest.Get("/groups", r.ListGroups),
		grest.Get("/groups/#email", r.GetGroup),
		grest.Post("/groups/#email", r.CreateGroup),
		grest.Put("/groups/#email", r.UpdateGroup),
	)
	if err != nil {
		return nil, err
	}

	r.rest.SetApp(router)
	return r.rest.MakeHandler(), nil
}
开发者ID:cafebazaar,项目名称:bahram,代码行数:23,代码来源:rest.go

示例8: main

func main() {

	// serve ng-admin angular app
	fs := http.FileServer(http.Dir("static"))
	http.Handle("/admin/", http.StripPrefix("/admin/", fs))

	db, err := sql.Open("sqlite3", "./blog.db")

	defer db.Close()

	if err != nil {
		panic(err)
	}

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

	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-Total-Count", "Origin"},
		AccessControlAllowCredentials: true,
		AccessControlMaxAge:           3600,
	})

	// initialize Entity REST API
	entityManager := eram.NewEntityDbManager(db)
	entityRestApi := era.NewEntityRestAPI(entityManager)

	router, err := rest.MakeRouter(
		rest.Get("/api/:entity", entityRestApi.GetAllEntities),
		rest.Post("/api/:entity", entityRestApi.PostEntity),
		rest.Get("/api/:entity/:id", entityRestApi.GetEntity),
		rest.Put("/api/:entity/:id", entityRestApi.PutEntity),
		rest.Delete("/api/:entity/:id", entityRestApi.DeleteEntity),
	)

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

	api.SetApp(router)

	http.Handle("/api/", api.MakeHandler())
	log.Fatal(http.ListenAndServe(":8080", nil))
}
开发者ID:Onefootball,项目名称:entity-rest-api,代码行数:50,代码来源:main.go

示例9: main

func main() {

	users := Users{
		Store: map[string]*User{},
	}

	books := Books{
		Store: map[string]*Book{},
	}

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	router, err := rest.MakeRouter(
		// users router
		rest.Get("/users", users.GetAllUsers),
		rest.Post("/users", users.PostUser),
		rest.Get("/users/:id", users.GetUser),
		rest.Put("/users/:id", users.PutUser),
		rest.Delete("/users/:id", users.DeleteUser),

		// user and book router
		rest.Get("/users/:id/books", users.GetUserAllBooks),

		// books router
		rest.Get("/books", books.GetAllBooks),
		rest.Post("/books", books.PostBook),
		rest.Get("/books/:id", books.GetBook),
		rest.Put("/books/:id", books.PutBook),
		rest.Delete("/books/:id", books.DeleteBook),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe(":8080", api.MakeHandler()))
}
开发者ID:cyy0523xc,项目名称:code,代码行数:36,代码来源:restful-api-user-book.go

示例10: main

func main() {

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	router, _ := rest.MakeRouter(
		rest.Post("/rest/c", postDataC),
		rest.Get("/rest/d", getDataD),
		rest.Put("/rest/e/msg/:host", putDataE),
	)
	//TEST call to dataplus initData()
	//log.Printf("Started on 9090")

	api.SetApp(router)
	log.Fatal(http.ListenAndServe(":8080", api.MakeHandler()))

}
开发者ID:jlandure,项目名称:go_server_mock,代码行数:16,代码来源:go_mock.go

示例11: 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

示例12: main

func main() {

	// Static Files
	fs := http.FileServer(http.Dir("app/dist"))
	http.Handle("/", fs)

	log.Println("Listening...")
	go http.ListenAndServe(":8080", nil)

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

	api.Use(&rest.CorsMiddleware{
		RejectNonCorsRequests: false,
		OriginValidator: func(origin string, request *rest.Request) bool {
			return true // origin == "http://127.0.0.1"
		},
		AllowedMethods: []string{"GET", "POST", "PUT", "OPTIONS", "DELETE"},
		AllowedHeaders: []string{
			"Accept", "Content-Type", "Authorization", "Origin"},
		AccessControlAllowCredentials: true,
		AccessControlMaxAge:           3600,
	})
	api.Use(AuthMiddleware())

	router, err := rest.MakeRouter(
		rest.Post("/auth/login", restapi.Login),
		rest.Post("/auth/register", restapi.Register),
		rest.Post("/api/importurl", restapi.ImportUrl),
		rest.Get("/api/documents", restapi.GetAllDocuments),
		rest.Post("/api/documents", restapi.PostDocument),
		rest.Get("/api/documents/:id", restapi.GetDocument),
		rest.Put("/api/documents/:id", restapi.PutDocument),
		rest.Delete("/api/documents/:id", restapi.DeleteDocument),
	)

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

	log.Printf("Port %s\n", conf.Port)
	log.Fatal(http.ListenAndServe(":"+conf.Port, api.MakeHandler()))
}
开发者ID:ds0nt,项目名称:markdown,代码行数:45,代码来源:api.go

示例13: main

func main() {
	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	router, err := rest.MakeRouter(
		rest.Post("/api/v1/images", HandleImageCreate),
		rest.Get("/api/v1/images", HandleImageList),
		rest.Post("/api/v1/instances", HandleInstanceCreate),
		rest.Post("/api/v1/instances/:instanceid", HandleInstanceStart),
		rest.Put("/api/v1/instances/:instanceid", HandleInstanceStop),
		rest.Get("/api/v1/instances", HandleInstanceList),
		rest.Get("/api/v1/instances/:instanceid", HandleInstanceInfo),
		rest.Delete("/api/v1/instances/:instanceid", HandleInstanceDestroy),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe(listen, api.MakeHandler()))
}
开发者ID:gitter-badger,项目名称:pangolin,代码行数:19,代码来源:pangolin-api.go

示例14: main

func main() {

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

	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	router, err := rest.MakeRouter(
		rest.Get("/reminders", i.GetAllReminders),
		rest.Post("/reminders", i.PostReminder),
		rest.Get("/reminders/:id", i.GetReminder),
		rest.Put("/reminders/:id", i.PutReminder),
		rest.Delete("/reminders/:id", i.DeleteReminder),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe(":8080", api.MakeHandler()))
}
开发者ID:jemkzheng,项目名称:go-json-rest-examples,代码行数:21,代码来源:main.go

示例15: RegisterApi

func (restapi *CyberBullyingEntryPointRestApiImpl) RegisterApi() {
	if restapi.Api == nil {
		restapi.SetApi(nil)
	}

	router, err := rest.MakeRouter(
		rest.Post("/api/signup", restapi.SignUpUser),
		rest.Post("/api/signin", restapi.SignUpUser),
		rest.Get("/api/#parentid/childinfo", restapi.GetChildInfo),
		rest.Post("/api/#parentid/childinfo", restapi.AddChildInfo),
		rest.Put("/api/#parentid/childinfo", restapi.UpdateChildInfo),
		rest.Get("/api/childbullydata/#parentid/#childid", restapi.GetChildBullyData),
		rest.Post("/api/childbullydata/#parentid/#childid", restapi.PostChildBullyData),
		rest.Post("/api/predict", restapi.PredictBullyData),
	)
	if err != nil {
		restapi.LoggerImplPtr.Error(err.Error())
		panic(err)
	}
	restapi.Api.SetApp(router)
}
开发者ID:maskofG,项目名称:anticyberbullying,代码行数:21,代码来源:cyberbullying-restapiImpl.go


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