Go Pentester - HTTP Servers(2)
Routing with the gorilla/mux Package
A powerful HTTP router and URL matcher for building Go web servers
https://github.com/gorilla/mux
Install package
go get -u github.com/gorilla/mux
Build sample 1:
package main import (
"fmt"
"github.com/gorilla/mux"
"net/http"
) func main() {
r := mux.NewRouter()
r.HandleFunc("/foo", func(w http.ResponseWriter, req *http.Request) {
fmt.Fprintln(w, "hi foo")
}).Methods("GET")
http.ListenAndServe(":8000", r)
}
Run the test sample 1.
Build sample 2: It's helpful to match and pass in parameters within the request patch (for example, when implementing a RESTful API)
package main import (
"fmt"
"github.com/gorilla/mux"
"net/http"
) func main() {
r := mux.NewRouter()
r.HandleFunc("/users/{user}", func(w http.ResponseWriter, req *http.Request) {
user := mux.Vars(req)["user"]
fmt.Fprintf(w, "hi %s\n", user)
}).Methods("GET")
http.ListenAndServe(":8000", r)
}
Run and test sample 2.
Build sample 3: Use regular expression to qualify the patterns passed.
package main import (
"fmt"
"github.com/gorilla/mux"
"net/http"
) func main() {
r := mux.NewRouter()
r.HandleFunc("/users/{user:[a-z]+}", func(w http.ResponseWriter, req *http.Request) {
user := mux.Vars(req)["user"]
fmt.Fprintf(w, "hi %s\n", user)
}).Methods("GET")
http.ListenAndServe(":8000", r)
}
Run and test sample 3.
Go Pentester - HTTP Servers(2)的更多相关文章
- Go Pentester - HTTP Servers(1)
HTTP Server Basics Use net/http package and useful third-party packages by building simple servers. ...
- Go Pentester - HTTP Servers(3)
Building Middleware with Negroni Reasons use middleware, including logging requests, authenticating ...
- Coping with the TCP TIME-WAIT state on busy Linux servers
Coping with the TCP TIME-WAIT state on busy Linux servers 文章源自于:https://vincent.bernat.im/en/blog/20 ...
- How To Restart timer service on all servers in farm
[array]$servers= Get-SPServer | ? {$_.Role -eq "Application"} $farm = Get-SPFarm foreach ( ...
- eclipse Run On Server 异常:could not load the Tomcat Server configuration at Servers\tomcat V5.0 Sertomcat
eclipse Run On Server 异常:could not load the Tomcat Server configuration at Servers\tomcat V5.0 Serto ...
- coderforces #387 Servers(模拟)
Servers time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- Servers
Servers¶ Server interface. class novaclient.v1_1.servers.Server(manager, info, loaded=False) Bases: ...
- 使用servers 启动项目时 ,一直处于启动中, 最后出现无法的问题。
使用eclipse 中的servers 配置了一个server 来启动项目, 发现无法启动 排除法: 去掉项目配置,单独启动该server ,发现可以启动, 说明是项目出现问题 但是项目并没有报错, ...
- servers中添加server时,看不到运行环境的选择。
servers中添加server时,看不到运行环境的选择. 主要原因是tomcat目录中的配置文件格式不对.
随机推荐
- Linux 进程间通信(IPC)总结
概述 一个大型的应用系统,往往需要众多进程协作,进程(Linux进程概念见附1)间通信的重要性显而易见.本系列文章阐述了 Linux 环境下的几种主要进程间通信手段. 进程隔离 进程隔离是为保护操作系 ...
- Hystrix Stream的监控页面不显示内容
打开Hystrix Stream页面,进入后,发现只有一行Unable to connect to Command Metric Stream. 因为springboot的默认路径不是 "/ ...
- android屏幕适配的全攻略2--支持手机各种屏幕密度dpi
如何为不同密度的屏幕提供不同的资源和使用密度独立的单位. 1 使用密度无关像素 坚决杜绝在布局文件中使用绝对像素来定位和设置大小.因为不同的屏幕有不同的像素密度,所以使用像素来设置控件大小是有问题的, ...
- 计算机网络之tcp与udp的区别
1.基于连接与无连接: 2.对系统资源的要求(TCP较多,UDP少):3.UDP程序结构较简单:4.流模式与数据报模式 :5.TCP保证数据正确性,可靠稳定,UDP可能丢包:6.TCP保证数据顺序,U ...
- Python实用笔记 (18)面向对象编程——类和实例
类和实例 面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法,但各 ...
- MongoDB快速入门教程 (2)
2.MongoDB的基本的CRUD操作 2.1.创建文档 在具体操作之前,想要知道有多少数据库,可以执行下面命令 show dbs 在mongodb中,数据库中包含的叫做集合(表),集合中存储的内容叫 ...
- DOM-BOM-EVENT(6)
6.BOM 6.1.什么是BOM? BOM(Browse Object Model),浏览器对象模型,没有相关标准,是约定俗成的东西,定义了一些操作浏览器的方法和属性,大部分方法都是通过window对 ...
- win10提示“无法设置移动热点 请打开WLAN”的解决方法
一位用户在使用Win10创意者操作系统过程中,遇到了无法开启移动热点的情况,开关呈灰色状态,而且提示:无法设置移动热点 请打开WLAN,该如何解决呢?该用户表示Wlan一直开着呀,感觉非常奇怪.接下来 ...
- 初探RabbitMQ消息队列
SpringBoot 是为了简化 Spring 应用的创建.运行.调试.部署等一系列问题而诞生的产物,自动装配的特性让我们可以更好的关注业务本身而不是外部的XML配置,我们只需遵循规范,引入相关的依赖 ...
- mat-paginatoor控件
pageNumber是点击搜索查询后,跟新的变量值. import { MatPaginatorIntl } from '@angular/material'; const getRangeLabel ...