本文整理匯總了Golang中github.com/hoisie/web.Context.NotFound方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.NotFound方法的具體用法?Golang Context.NotFound怎麽用?Golang Context.NotFound使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hoisie/web.Context
的用法示例。
在下文中一共展示了Context.NotFound方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: api
func api(ctx *web.Context, username string) string {
user, err := getUser(username)
ctx.SetHeader("Content-Type", "application/prs.kevinburke.snapchat-v1+json", true)
if err != nil {
checkError(err)
ctx.NotFound("User not found")
return ""
}
friends, err := getFriendsById(user.Id)
checkError(err)
var links Links
var users []User
users = append(users, *user)
for i := 0; i < len(friends.Friends); i++ {
friend := friends.Friends[i]
link := Link{friend.UserId, friend.FriendId, friend.Index}
links.Links = append(links.Links, link)
user, err := getUserById(friend.UserId)
checkError(err)
users = append(users, *user)
}
response := Response{links.Links, users}
bytes, err := json.Marshal(response)
checkError(err)
return string(bytes)
}
示例2: downloader
func downloader(ctx *web.Context, key string) {
updateRemoteAddr(ctx)
up, ok := uploadRequests[key]
if !ok {
ctx.NotFound("key doesn't exist")
return
}
up.wait <- "connected"
result := "ng"
defer func() { up.wait <- result }()
mr, err := up.request.MultipartReader()
if err != nil {
ctx.Abort(500, err.Error())
return
}
p, err := mr.NextPart()
if p.FormName() == "size" {
fileSize, err := ioutil.ReadAll(p)
if err == nil {
fileSize, err := strconv.ParseInt(string(fileSize), 10, 64)
if err == nil && fileSize >= 0 {
ctx.SetHeader("Content-Length", strconv.FormatInt(fileSize, 10), true)
}
}
}
p, err = mr.NextPart()
if err != nil {
ctx.Abort(500, err.Error())
return
}
if p.FormName() != "file" {
ctx.Abort(500, "invalid POST (upload) request")
return
}
if contentType := p.Header.Get("Content-Type"); contentType != "" {
ctx.SetHeader("Content-Type", contentType, true)
}
ctx.SetHeader("Content-Disposition", "attachment; filename="+p.FileName(), true)
_, err = io.Copy(ctx, p)
if err == nil {
result = "ok"
} else {
// XXX: may expose too many infomation (such as client IP address)
//result = err.Error()
}
}
示例3: dnsmasq
func dnsmasq(ctx *web.Context, action string, ip string) string {
actions := map[string]bool{
"add": true,
"del": true,
"old": true,
"init": false,
"tftp": false,
}
response := ""
if actions[action] {
if !kerberos() {
log.Printf("Unable to process %s", action)
ctx.NotFound("That sucks")
return ""
}
tv := Nsupdate{
Server: cfg.Dns.Nsrvs,
Ip: ip,
Host: ctx.Params["host"],
Domain: ctx.Params["domain"],
Ttl: cfg.Dns.Ttl,
Mac: ctx.Params["mac"],
}
IP := net.ParseIP(ip)
if IP.To4() == nil && IP.To16() != nil {
tv.Rr = "AAA"
var expanded string
for u := 0; u < len(IP); u++ {
x := fmt.Sprintf("%x", IP[u])
if len(x) != 2 {
expanded += "0"
}
expanded += x
if u%2 != 0 && u < (len(IP)-1) {
expanded += ":"
}
}
tv.Ip = fmt.Sprintf("%s", expanded)
for _, r := range reverse(expanded) {
c := string(r)
if c != ":" {
tv.Ptr += fmt.Sprintf("%s.", c)
}
}
tv.Ptr += "ipv6.arpa"
} else {
s := strings.Split(ip, ".")
tv.Rr = "A"
tv.Ptr = fmt.Sprintf("%s.%s.%s.%s.in-addr.arpa", s[3], s[2], s[1], s[0])
}
if len(tv.Host) < 2 {
log.Print("nil host!")
addr, _ := net.LookupAddr(ip)
if addr != nil && cfg.Service.Debug {
log.Printf("LookupAddr: %d%s", len(addr), addr)
}
}
var output bytes.Buffer
var stderr bytes.Buffer
nsupdate := exec.Command("nsupdate", cfg.Dns.Nsupdateflags)
nsin, err := nsupdate.StdinPipe()
if err != nil {
log.Fatalf("unable to create pipe: %s", err)
}
nsupdate.Stdout, nsupdate.Stderr = &output, &stderr
nsupdate.Start()
if action == "add" || action == "old" {
err = tmpl.Execute(nsin, tv)
if err != nil {
log.Fatalf("template execution failed: %s", err)
}
response = fmt.Sprintf("%s %s\n", ip, action)
}
if action == "del" {
err := tmpl.ExecuteTemplate(os.Stderr, "dhcplistener.nsupdate.del", tv)
if err != nil {
log.Fatalf("template execution failed: %s", err)
}
response = fmt.Sprintf("%s %s\n", ip, action)
}
nsin.Close()
nsupdate.Wait()
if cfg.Service.Debug {
log.Printf("%s", output)
log.Printf("%s", stderr)
}
//.........這裏部分代碼省略.........