func (w *WorldController) Say(r *knot.Request) interface{} { r.ResponseConfig().OutputType = knot.OutputHtml s := "<b>Hello World</b> " name := r.Query("name") if name != "" { s = s + " " + name } s += "</br>" return s }
func (w *WorldController) Cookie(r *knot.Request) interface{} { r.ResponseConfig().OutputType = knot.OutputHtml cvalue := "" cookiename := "mycookie" c, _ := r.Cookie(cookiename) if c == nil { r.SetCookie(cookiename, "Arief Darmawan", 30*24*time.Hour) } else { cvalue = c.Value c.Value = "Arief Darmawan" + time.Now().String() c.Expires = time.Now().Add(24 * 30 * time.Hour) } return "Cookie value is " + cvalue }
func (w *WorldController) Json(r *knot.Request) interface{} { r.ResponseConfig().OutputType = knot.OutputJson return struct{ ID, Title string }{"JsonID 00001", "Json Row 01 - Title"} }
func (w *WorldController) Session(r *knot.Request) interface{} { r.ResponseConfig().OutputType = knot.OutputHtml s := r.Session("NameAndTime", "").(string) r.SetSession("NameAndTime", "Arief Darmawan : "+time.Now().String()) return "Session value is " + s }