码迷,mamicode.com
首页 > 其他好文 > 详细

golang 获取get参数

时间:2018-03-02 23:12:42      阅读:314      评论:0      收藏:0      [点我收藏+]

标签:items   ant   item   ons   serve   param   nan   ssi   main   

package main

import (
"log"
"net/http"
)

func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8081", nil)
}

func handler(w http.ResponseWriter, r *http.Request) {

keys, ok := r.URL.Query()["key"]

if !ok || len(keys) < 1 {
    log.Println("Url Param ‘key‘ is missing")
    return
}

// Query()["key"] will return an array of items,
// we only want the single item.
key := keys[0]

log.Println("Url Param ‘key‘ is: " + string(key))

}

golang 获取get参数

标签:items   ant   item   ons   serve   param   nan   ssi   main   

原文地址:https://www.cnblogs.com/Dennis-mi/p/8495175.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!