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


Golang rest.Get函数代码示例

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


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

示例3: main

/*
Microservice for accessing data
*/
func main() {
	api := rest.NewApi()
	api.Use(rest.DefaultDevStack...)
	api.Use(
		&rest.AuthBasicMiddleware{
			Realm:         "Smart Alarm Clock REST API",
			Authenticator: auth.AuthenticateByFile,
			Authorizator:  auth.AuthorizeRequest})
	router, err := rest.MakeRouter(
		rest.Get("/test/:time", view.GetJSONMessage),
		rest.Get("/calendar/next/:id", view.GetNextCalendarEntry),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	apilog.Init()
	calcom.InitApis()
	log.Fatal(
		http.ListenAndServeTLS(":1443",
			"/etc/sac/keys/cert.pem",
			"/etc/sac/keys/key.pem",
			api.MakeHandler(),
		),
	)
}
开发者ID:rugo,项目名称:sacapi,代码行数:29,代码来源:saccalendar.go

示例4: Route

func Route() (rest.App, error) {

	return rest.MakeRouter(
		// 新增某个服务
		rest.Post("/apps", restGuarder(handler.CreateAppsHandler)),
		// 获取所有服务的基本信息
		rest.Get("/apps", restGuarder(handler.GetInfoAppsHandler)),
		// TODO 获取某一个服务的详细信息
		rest.Get("/apps/*appId", restGuarder(handler.GetSingleAppsHandler)),
		// 删除某一个服务的所有实例
		rest.Delete("/apps/*appId", restGuarder(handler.DeleteAppsHandler)),
		// 新增或者更新一批服务
		rest.Post("/apps/updater", restGuarder(handler.CreateOrUpdateAppsHandler)),
		// 回滚一批服务
		rest.Post("/apps/rollback", restGuarder(handler.RollbackAppsHandler)),
		// 新增一批组信息
		rest.Post("/groups", restGuarder(handler.DeployGroupsHandler)),

		// 给新增容器获取一个IP
		rest.Get("/ipholder/*cId", restGuarder(handler.CreateIpForContainer)),
		// 给删除容器释放所占用的IP
		rest.Delete("/ipholder/*cId", restGuarder(handler.DeleteIpForContainer)),

		// 填写某个容器信息
		rest.Post("/containers", restGuarder(handler.CreateContainerInfo)),
		// 更新容器状态
		rest.Post("/containers/:cId/:cState", restGuarder(handler.UpdateStateContainerInfo)),
		// 软删除容器
		rest.Delete("/containers/soft/*cId", restGuarder(handler.MaskContainerInfo)),
	)
}
开发者ID:zufangzi,项目名称:chaos,代码行数:31,代码来源:route.go

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

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

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

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

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

示例10: Init

func (a *RestAdapterImplementation) Init(db models.DB) (router rest.App, err error) {
	a.db = db

	router, err = rest.MakeRouter(
		rest.Get("/feeds/:id", a.GetFeed),
		rest.Get("/feeds", a.GetAllFeeds),
		rest.Get("/tags", a.GetAllTags),
	)
	return
}
开发者ID:mlapierre,项目名称:rss-reader-api,代码行数:10,代码来源:rest_adapter.go

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

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

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

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

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


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