go 练习:HTTP 处理
这篇文章只是联系go指南时的笔记吧。
package main import (
"fmt"
"log"
"net/http"
) type String string type Struct struct{
Greeting string
Punct string
Who string
} func main(){
http.Handle("/string",String("aaaaaaaaaaaaaaaaaaaa2"))
http.Handle("/struct", Struct{
Greeting: "Hello",
Punct: "",
Who: "gopher",
})
log.Fatal(http.ListenAndServe("localhost:4000",nil))
} func (s String) ServeHTTP(w http.ResponseWriter, r *http.Request){
fmt.Fprint(w,s)
}
func (s Struct) ServeHTTP(w http.ResponseWriter, r *http.Request){
fmt.Fprint(w,s)
}
上面的http.handle() 里面的url,如果重复的话,会报错
随机推荐
- linux内核模块编译makefile
linux内核可加载模块的makefile 在开发linux内核驱动时,免不了要接触到makefile的编写和修改,尽管网上的makefile模板一大堆,做一些简单的修改就能用到自己的项目上,但是,对 ...
- mysqdump+binlog恢复数据
备份全库 [root@db01 b]# mysqldump -uroot -poldboy123 -A > /b/full.sql Warning: Using a password on th ...
- <? extends T> 及 <? super T> 重温
<? extends T> 及<? super T> 重温 本文针对泛型中<? extends T> 及<? super T>的主要区别及使用用途进行讨 ...
- 【原创】python+selenium,用xlrd,读取excel数据,执行测试用例
# -*- coding: utf-8 -*- import unittest import time from selenium import webdriver import xlrd,xlwt ...
- SQLAlchemy的应用创建
1.首先创建app文件夹 同django 创建app 一样 创建文件 在创建的views中写入两个蓝图函数为了操作数据库的增删改查 acc.py from flask import Blueprint ...
- P1972 [SDOI2009]HH的项链[离线+树状数组/主席树/分块/模拟]
题目背景 无 题目描述 HH 有一串由各种漂亮的贝壳组成的项链.HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH 不断地收集新的贝壳,因此,他的项链 ...
- Java动态代理演变之路
1.什么是代理? 代理,英文成文Proxy.意思是你不用去做,别人代替你去处理.比如有人想找明星周董去唱歌,他需要做签约.讨论.唱歌和付款等等过程,但真正周董擅长的事情是唱歌,其他的事情可以交代给他的 ...
- phantomJS+Python 隐形浏览器
phantomjs解压后,把文件夹bin中的phantomjs.exe移到python文件夹中的Scripts中 实例: from selenium import webdriver driver = ...
- Docker创建mysql镜像
原文: https://blog.csdn.net/uk8692/article/details/49386679 https://blog.csdn.net/qq362228416/article/ ...
- Python常用标准库函数
math库: >>> import math >>> dir(math) ['__doc__', '__loader__', '__name__', '__pack ...