本文整理匯總了Golang中github.com/hoisie/web.Context.WriteString方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.WriteString方法的具體用法?Golang Context.WriteString怎麽用?Golang Context.WriteString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hoisie/web.Context
的用法示例。
在下文中一共展示了Context.WriteString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Put
func (h *RestQueueHandler) Put(ctx *web.Context, val string) {
queue := redisq.NewRedisQueue(h.redis, val)
if !queue.Exists() {
h.logger.Printf("Queue [%s] didn't existst, will be ceated.", val)
}
if mesg, ok := ctx.Params["value"]; ok {
var i interface{}
err := json.Unmarshal([]byte(mesg), &i)
if err != nil {
writeError(ctx, 400, JsonDecodeError)
return
}
err = queue.Put(i)
if err != nil {
writeError(ctx, 500, PostError)
if Settings.Debug {
debug := fmt.Sprintf("Debug: %s", err)
ctx.WriteString(debug)
}
h.logger.Printf("Put message into [%s] Error:%s", val, err)
return
}
h.logger.Printf("Put message into queue [%s]", val)
} else {
writeError(ctx, 400, LackPostValue)
}
}
示例2: adminPost
func adminPost(ctx *web.Context) {
level := ctx.Params["godlevel"]
godlevel := godHash(level)
if ctx.Params["what"] == "login" {
if godlevel == admin_pass {
ctx.SetSecureCookie("godlevel", level, 3600)
ctx.Redirect(301, "/admin")
return
}
ctx.SetSecureCookie("godlevel", "fefe", 3600)
ctx.Redirect(301, "/")
return
}
if !checkGodLevel(ctx) {
ctx.SetSecureCookie("godlevel", "fefe", 3600)
ctx.Redirect(301, "/")
return
}
if ctx.Params["what"] == "post" {
err := createNewPost(ctx.Params["content"])
if err != nil {
ctx.WriteString("couldn't post: " + err.Error())
ctx.WriteString("<br><br><A href='/'>Index</a>")
return
}
ctx.WriteString(successpage)
return
}
}
示例3: Publish
func (c *Controller) Publish(ctx *web.Context) {
if !c.sessionManager.LoggedIn(ctx) {
ctx.Redirect(303, "/login")
return
}
ctx.WriteString(c.Page("publish.html"))
}
示例4: Get
func (h *RestQueueHandler) Get(ctx *web.Context, val string) {
queue := redisq.NewRedisQueue(h.redis, val)
if !queue.Exists() {
writeError(ctx, 404, QueueNotFound)
return
}
if queue.Empty() {
writeError(ctx, 400, EmptyQueue)
return
}
mesg, err := queue.GetNoWait()
if err != nil {
writeError(ctx, 500, GetError)
if Settings.Debug {
debug := fmt.Sprintf("Debug: %s", err)
ctx.WriteString(debug)
}
h.logger.Printf("Dequeue from <%s> Error:%s", val, err)
return
}
resp, _ := json.Marshal(mesg)
//mesg.(type) is iteface{}
//resp.(type) is []byte
ctx.SetHeader("Content-Type", "application/json; charset=UTF-8", true)
ctx.WriteString(string(resp))
}
示例5: Render
func Render(ctx *web.Context, tmpl string, config *Config, name string, data interface{}) {
tmpl = filepath.Join(config.Get("datadir"), tmpl)
ctx.WriteString(mustache.RenderFile(tmpl,
map[string]interface{}{
"config": config,
name: data}))
}
示例6: List
func (h *RestQueueHandler) List(ctx *web.Context) {
var keys []string
keys, _ = h.redis.Keys("*")
resp, _ := json.Marshal(keys)
ctx.SetHeader("Content-Type", "application/json; charset=UTF-8", true)
ctx.WriteString(string(resp))
}
示例7: Sendstatic
func Sendstatic(ctx *web.Context, val string) {
file, _err := ioutil.ReadFile("static/" + val)
if _err != nil {
return
}
filetype := strings.Split(val, ".")
ctx.ContentType(filetype[len(filetype)-1])
ctx.WriteString(string(file))
}
示例8: hello
func hello(ctx *web.Context, num string) {
flusher, _ := ctx.ResponseWriter.(http.Flusher)
flusher.Flush()
n, _ := strconv.ParseInt(num, 10, 64)
for i := int64(0); i < n; i++ {
ctx.WriteString("<br>hello world</br>")
flusher.Flush()
time.Sleep(1e9)
}
}
示例9: uploader
func uploader(ctx *web.Context, key string) {
updateRemoteAddr(ctx)
if _, ok := uploadRequests[key]; ok {
// key exists
ctx.Forbidden()
return
}
wait := make(chan string)
defer delete(uploadRequests, key)
uploadRequests[key] = uploadRequest{ctx.Request, wait}
var result string
select {
case result = <-wait:
case <-time.After(WAIT_CLIENT_TIMEOUT):
result = "wait client timeout"
}
if result == "connected" {
// wait actual result
result = <-wait
}
var body string
if xrw := ctx.Request.Header.Get("X-Requested-With"); xrw == "XMLHttpRequest" {
body = "{\"result\": \"" + result + "\"}\n"
ctx.SetHeader("Content-Type", "application/json", true)
} else {
tmpl, err := template.New("uploader").Parse(uploadTemplate)
if err != nil {
panic(err)
}
var buf bytes.Buffer
tmpl.Execute(&buf, UploadTemplateValue{result})
body = buf.String()
}
if result == "ok" {
ctx.WriteString(body)
} else {
ctx.Abort(500, body)
ctx.Request.Body.Close()
}
}
示例10: handleFilter
func handleFilter(ctx *web.Context, val string) {
order_id, err := strconv.ParseInt(ctx.Params["id"], 10, 64)
if err != nil {
// handle error
}
facts := getFactsFromRedis(order_id)
response, err := json.Marshal(facts)
if err != nil {
// handle error
}
ctx.WriteString(string(response[:]))
}
示例11: Clear
func (h *RestQueueHandler) Clear(ctx *web.Context, val string) {
queue := redisq.NewRedisQueue(h.redis, val)
if !queue.Exists() {
writeError(ctx, 404, QueueNotFound)
return
}
err := queue.Clear()
if err != nil {
writeError(ctx, 500, ClearError)
if Settings.Debug {
debug := fmt.Sprintf("Debug: %s", err)
ctx.WriteString(debug)
}
h.logger.Printf("Delete queue [%s] Error:%s", val, err)
return
}
h.logger.Printf("Queue [%s] deleted sucess", val)
}
示例12: LoginPost
func (c *Controller) LoginPost(ctx *web.Context) {
user := ctx.Params["user"]
pass := ctx.Params["pass"]
dest := "/login"
if c.sessionManager.Login(ctx, user, pass) {
ctx.WriteString(c.themeEngine.Theme("You are logged in"))
dest = "/publish"
} else {
ctx.WriteString(c.themeEngine.Theme("Incorrect Username/Password"))
}
ctx.WriteString("<meta HTTP-EQUIV=\"REFRESH\" content=\"2; url=" + dest + "\">")
}
示例13: editPost
func editPost(ctx *web.Context) {
if !checkGodLevel(ctx) {
ctx.Redirect(301, "/")
return
}
Db := DBGet()
defer Db.Close()
id, _ := strconv.ParseInt(ctx.Params["postid"], 10, 64)
post, err := Db.GetPost(id)
if err != nil {
ctx.WriteString("couldn't load post with given id!")
return
}
post.Content = ctx.Params["content"]
_, err = Db.StorePost(&post)
if err != nil {
ctx.WriteString("couldn't store post!")
return
}
ctx.WriteString(successpage)
}
示例14: index
func index(webContext *web.Context) {
webContext.WriteString("Powered by <a href=\"http://www.github.com/Altonymous/forum/\">Altonymous forum!</a>")
}
示例15: hello
func hello(ctx *web.Context, val string) {
ctx.WriteString("hello " + val)
}