如何在Golang中处理动态URL [英] How to Handle dynamic URL in Golang

查看:347
本文介绍了如何在Golang中处理动态URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Go Web应用,该应用中需要处理/person/(any_name)之类的URL.作为Golang的新手,我不知道该怎么做.请帮助我.

I am creating a Go web app in which I need to handle a URL like /person/(any_name). As a newbie in Golang, I don't know how to do so. Please help me.

推荐答案

您应该考虑使用gorilla/mux软件包来尝试执行操作. github摘录显示了 https://github.com/gorilla/mux

You should look into using gorilla/mux package for what you are trying to do. An excerpt from the package github shows https://github.com/gorilla/mux

r := mux.NewRouter()
r.HandleFunc("/products/{key}", ProductHandler)
r.HandleFunc("/articles/{category}/", ArticlesCategoryHandler)
r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler)

这篇关于如何在Golang中处理动态URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆