阅读权限90
最后登录2023-8-31
在线时间19 小时
积分882
注册时间2019-3-12
精华0
主题0
UID121373
帖子119
金币1209
威望0
贡献0
技术0
活跃182
论坛贵宾VIP-永久权限
- 贡献
- 0
- 技术
- 0
- 活跃
- 182
- 在线时间
- 19 小时
|
发表于 2019-3-14 11:19:52
|
显示全部楼层
package main
import (
"fmt"
"net/http"
)
type Database struct {
Url string
}
func NewDatabase(url string) Database {
return Database{url}
}
func main() {
db := NewDatabase("localhost:5432")
http.HandleFunc("/hello", hello(db))
http.ListenAndServe(":3000", nil)
}
func hello(db Database) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, db.Url)
}
} |
|