當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Cookie.InitCooike方法代碼示例

本文整理匯總了Golang中ibookings/utils.Cookie.InitCooike方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cookie.InitCooike方法的具體用法?Golang Cookie.InitCooike怎麽用?Golang Cookie.InitCooike使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ibookings/utils.Cookie的用法示例。


在下文中一共展示了Cookie.InitCooike方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: dispatchController

func dispatchController(w http.ResponseWriter, r *http.Request) {
	web := e.HTTP{Request: r, ResponseWriter: w}

	// defer func() {
	// 	log.Println("defer func is run")
	// 	e := recover()
	// 	if r != nil {
	// 		log.Println("recover : ", e)
	// 	}
	// }()

	pathInfo := strings.Trim(r.URL.Path, "/")
	parts := strings.Split(pathInfo, "/")
	r.ParseForm()
	cookie := u.Cookie{HTTP: web}
	cookie.InitCooike()
	log.Println((parts))

	if parts[0] != "" {
		log.Println("檢測到url後麵帶/")
		var controllerName = ""
		var methodName = ""
		var formKey = ""
		var formValue = ""
		//處理類似URLxxx.com/login/exit/u/[email protected]
		for index, value := range parts {
			switch index {
			case 0:
				//類名字
				controllerName = value
			case 1:
				//方法名字
				methodName = strings.Title(value)
			default:
				if index%2 == 0 {

					formKey = value

				} else {

					formValue = value

				}
				if formKey != "" && formValue != "" {
					log.Println("表單Key" + formKey)
					log.Println("表單Value" + formValue)
					r.Form.Add(formKey, formValue)
					//r.Form.Add("1", "1")
					log.Println(r.Form)
					formKey = ""
					formValue = ""
				}

			}

		}

		log.Println("controllerName:", controllerName)
		log.Println("methodName:", methodName)
		controllerClass, ok := Cotrollers[controllerName]
		if !ok {
			log.Print("沒有找到Controller:", controllerName)
			controllerClass = Error{}
		}

		controller := reflect.ValueOf(controllerClass)
		if methodName == "" {
			if r.Method == "GET" {
				methodName = "Get"
			} else if r.Method == "POST" {
				methodName = "Post"
			}
		}
		method := controller.MethodByName(methodName)
		if method.IsValid() {
			// requestValue := reflect.ValueOf(r)
			// responseValue := reflect.ValueOf(w)
			log.Println(controller)

			webValue := reflect.ValueOf(web)
			httpField := controller.Elem().FieldByName("HTTP")

			log.Println("httpField", httpField, httpField.CanSet())
			httpField.Set(webValue)
			// fieldElem := httpField.Elem()
			// log.Println("Field can Set", fieldElem.CanSet())
			// fieldElem.Set(webValue)
			// responseWriter := controller.FieldByName("ResponseWriter")
			// responseWriter.Set(responseWriter)
			//method.Call([]reflect.Value{responseValue, requestValue})
			method.Call(nil)
		} else {
			log.Print("沒有找到Method:", methodName)
		}
	} else {
		index := IndexController{HTTP: web}
		index.Index()

	}
}
開發者ID:jjjachyty,項目名稱:ibookings,代碼行數:100,代碼來源:Dispatch.go


注:本文中的ibookings/utils.Cookie.InitCooike方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。