- UID
- 74214
- 在线时间
- 0 小时
- 最后登录
- 2025-3-3
- 注册时间
- 2012-3-7
- 宅魂
- 293 点
- 贡献
- 83 点
- 宅币
- 2308 枚
- 灵石
- 0 块
- 元气(技能点)
- 1 点
- 活跃
- 3 ℃
- 听众
- 5
- 收听
- 1
该用户从未签到
序章
- 积分
- 3486
|
最近在玩go语言,贴个我测试helloworld的例子来给大家瞧瞧
[mw_shl_code=c,true]package main
import (
"fmt"
"net/http"
"sync"
)
type URLStore struct {
urls map[string]string
mu sync.RWMutex
// func (s *URLStore) Get(key string) string {
// s.mu.Rlock()
// url := s.urls[key]
// s.mu.RUnlock()
// return url
// }
// func (s *URLStore) Set(key,url string) bool{
// s.mu.Lock()
// _, present := s.urls[key]
// if present {
// s.mu.Unlock()
// return false
// }
// s.urls[key] = url
// s.mu.Unlock()
// return true
// }
}
func Hello(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "8080 is avaliable,Master !")
}
func deafult(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello,World")
}
// func Add(w http.ResponseWriter, r *http.Request) {
// url := r.FormValue("url")
// key := store.Put(url)
// fmt.Fprintf(w, "http://localhost:8080/%s", key)
// }
func main() {
fmt.Printf("%s\n%s\n%s","I am working ","open browser,enter url localhost:8080/shabuwenzi,","Master")
http.HandleFunc("/", deafult)
http.HandleFunc("/shabuwenzi", Hello)
// http.HandleFunc("/add", Add)
http.ListenAndServe(":8080", nil)
}
[/mw_shl_code]
貌似传不了附件,不然能给个exe看看
|
|