最近在玩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看看#46t
绯色基 发表于 2013-10-16 23:16话说为什么go语言好像很不受见待的样子
我在不少网站见到都是喷来着
...
不受见带是正常的,因为没人会很乐意的去学一个新的东西
喷到是不太常见,可能是我不大关注的缘故
总得来说要过几年再来看看,go压的未来是大数据的,因为它的主打是高并发,如果未来不是这个趋势,或者它做的不好就只能完蛋了,现在谁都说不好
[查看全文]