Go Pentester - HTTP Servers(1)
HTTP Server Basics
Use net/http package and useful third-party packages by building simple servers.
Building a Simple Server
package main import (
"fmt"
"net/http"
) func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello %s\n", r.URL.Query().Get("name"))
} func main() {
http.HandleFunc("/hello", hello)
http.ListenAndServe(":8000",nil)
}
Run the above program and test it.
curl -i http://localhost:8000/hello?name=eric

You can also use http.ListenAndServeTLS(), which will start a server using HTTPS and TLS.
Build a Simple Router
package main import (
"fmt"
"net/http"
) type router struct {
} func (r *router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case "/a":
fmt.Fprintf(w, "Executing /a\n")
case "/b":
fmt.Fprintf(w, "Executing /b\n")
case "/c":
fmt.Fprintf(w, "Executing /c\n")
default:
http.Error(w, "404 Not Found", 404)
}
} func main() {
var r router
http.ListenAndServe(":8000", &r)
}
Test the above program by the following commands.
curl http://localhost:8000/a
curl http://localhost:8000/d

Building simple Middleware
A simple middleware, which is a sort of wrapper that will execute on all incoming requests regardless of the destination function.
package main import (
"fmt"
"log"
"net/http"
"time"
) type logger struct {
Inner http.Handler
} func (l *logger) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log.Printf("start %s\n", time.Now().String())
l.Inner.ServeHTTP(w,r)
log.Printf("finish %s",time.Now().String())
} func hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello\n")
} func main() {
f := http.HandlerFunc(hello)
l := logger{Inner: f}
http.ListenAndServe(":8000", &l)
}
Run the program and issue a request.
curl http://localhost:8000

Go Pentester - HTTP Servers(1)的更多相关文章
- Go Pentester - HTTP Servers(2)
Routing with the gorilla/mux Package A powerful HTTP router and URL matcher for building Go web serv ...
- 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目录中的配置文件格式不对.
随机推荐
- cookie与session区别?
参考 cookie与session的区别是什么 Java中Cookie的使用(Cookie 和Session的区别) 什么是会话? 用户开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭 ...
- 循序渐进VUE+Element 前端应用开发(11)--- 图标的维护和使用
在VUE+Element 前端应用中,图标是必不可少点缀界面的元素,因此整合一些常用的图标是非常必要的,还好Element界面组件里面提供了很多常见的图标,不过数量不是很多,应该是300个左右吧,因此 ...
- 一文搞定Redis五大数据类型及应用场景
本文学习知识点 redis五大数据类型数据类型:string.hash.list.set.sorted_set 五大类型各自的应用场景 @TOC 1. string类型 1-1 string类型数据的 ...
- Linux下安装java环境
准备工作: linux环境 xshell6 1.在Windows本地www,oracle.com下载对应的linux系统的JDK安装包,我下载的是 2.下载下来后,通过xftp远程传输到linux服务 ...
- WeChair项目Beta冲刺(8/10)
团队项目进行情况 1.昨日进展 Beta冲刺第八天 昨日进展: 前后端并行开发,项目按照计划有条不絮进行 2.今日安排 前端:扫码占座功能和预约功能并行开发 后端:扫码占座后端逻辑开发,编码使用 ...
- 安装mysql报错:遇到缺少vcruntime140_1.dll文件
把vcruntime140_1.dll文件放到System32 ,和System64就行 文件地址为:C:\Windows\System32 直接百度下载放进去就行
- java 中对hashmap进行排序
public class HashMapSort { public static void main(String[] args) { HashMap<Integer, Student> ...
- Python3-sys模块-解释器相关参数与函数
Python3中的sys模块提供了访问由解释器使用和维护的一些变量和与解释器强烈交互的函数 sys.argv 获取传递给Python脚本的参数列表,sys.argv[0]代表脚本本身,sys.argv ...
- P1640 [SCOI2010]连续攻击游戏【并查集】
题目描述 lxhgww最近迷上了一款游戏,在游戏里,他拥有很多的装备,每种装备都有2个属性,这些属性的值用[1,10000]之间的数表示.当他使用某种装备时,他只能使用该装备的某一个属性.并且每种装备 ...
- 资深阿里程序员一一为你解刨Web前端知识体系结构,付出与收获成正比!
只要接触过前端,都会指导web前端的知识主要由三部分组成:分别为静态html,样式css,动态javascript(简称js)这三大部分组成.其三部分组成的一个体系的复杂程度不亚于其他一门技术的复杂程 ...