先下载Go Micro框架
go get -v github.com/micro/go-micro
![](https://xiahualou.oss-cn-shanghai.aliyuncs.com/img/20191225143652.png)
启动一个简单的Server
package main
import (
"github.com/micro/go-micro/web"
"net/http"
)
func main() {
/*第一种方法,新建一个Option类型的函数,作为参数传递给NewService方法
addr := func(o *Options){
o.Address = "8001"
}
server := web.NewService(addr)
*/
/*第二种方法,使用官方提供的简易方法web.Address(":8001")
func Address(a string) Option {
return func(o *Options) {
o.Address = a
}
} //其实是对第一种方法的简易封装
*/
server := web.NewService(web.Address(":8001")) //参数为不定长参数Option type Option func(o *Options)
server.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
writer.Write([]byte("hello world"))
})
server.Run()
}