duandun3178 2017-11-22 00:20
浏览 178

有没有一种方法可以使用mux路由来选择处理程序,而无需对golang使用http listenAndServe?

There are a lot of mux routers for golang. All of the ones I've found assume that I'm building my own http server in go. However, I would like to use aws apigateway as the external layer and have it forward the method, path, query parameters to a lambda function that I have deployed with apex (go shim for aws lambda functions). All the api gateway endpoints will forward to one lambda function so that there are fewer things to hook up, like permissions and so forth.

So I would like to use nice mux libraries for their ability to parse regex or path variables, but use them inside the lambda and be able to invoke the correct handler based on the url path.

Most of the mux routers have a usage like this:

router := NewRouter()
router.Add("GET", "/my_path/:id", MyHandler)

Where MyHandler is a type of http.HandlerFunc

Then the server is started with something like http.ListenAndServe(port, router)

But in aws lambda there is no server to start, I would just like to use the mux to find the handler that I should be calling.

  • 写回答

2条回答 默认 最新

  • doulin2947 2018-03-20 02:46
    关注

    I have created a lib for this purpose.

    The basic idea is to transform apigateway request context which is a json object into http.Request

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题