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目录中的配置文件格式不对.
随机推荐
- strcmp函数的两种实现
strcmp函数的两种实现,gcc测试通过. 一种实现: C代码 #include<stdio.h> int strcmp(const char *str1,const char *s ...
- WeChair项目Beta冲刺(10/10)
团队项目进行情况 1.昨日进展 Beta冲刺第十天 昨日进展: 项目完工 2.今日安排 对小程序进行测试,同时对项目进行总结,并整理博客材料等 3.燃尽图 4.展示Git当日代码记录 详情 ...
- powershell代码混淆绕过
目前大多数攻击者已经将PowerShell 利用在了各种攻击场景中,如内网渗透,APT攻击甚至包括现在流行的勒索软件中.powershell的功能强大且调用方式十分灵活,灵活使用powershell可 ...
- js Date format(日期格式化:yyyy-MM-dd HH:mm:ss.S)
今天在做日期显示的时候,那个显示格式困扰了很久,各种组件都尝试了,总是不如意,最后自己网上找了一个,然后稍微修改一下,感觉这个Util挺常用的,这里mark一下 Date.prototype.form ...
- linux下的c语言编程学习笔记
视频参看csdn学院王阳和下面的linux环境下c语言编程基础相当的经典,其中王阳的视频讲的很好,相当的经典 编译hellogcc.c需要依赖/home目录下的头文件 为了避免同一个文件被includ ...
- GraphicsLab Project 之 Screen Space Planar Reflection
作者:i_dovelemon 日期:2020-06-23 主题:Screen Space Planar Reflection, Compute Shader 引言 前段时间,同事发来一篇讲述特化版本的 ...
- dubbo源码解析之负载均衡
在分布式系统中,负载均衡是必不可少的一个模块,dubbo 中提供了五种负载均衡的实现,在阅读这块源码之前,建议先学习负载均衡的基础知识.把看源码当做一个印证自己心中所想的过程,这样会得到事半功倍的效果 ...
- vs2010调试运行时弹出对话框:系统找不到指定文件
很多时候,我们会将一些低版本IDE编译过的项目,搬迁到VS2010 ,那么会存在很多编译,调试问题.[1] 编译成功了.可是无法调试 . . 显示 无法启动程序“...........\t ...
- java方法中开启一个线程
很多业务场景下需要你在一个方法中去开启一个线程,去跑一些处理时间较长的代码,这样调用方就不必经过长时间的等待了.好了 话不多说 先上代码: package test; public class Th ...
- python server端并发聊天
---------------------------server.py---------------------import socketserver class MyServer(socketse ...