<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          nosurfGo 的 CSRF 中間件

          聯合創(chuàng)作 · 2023-09-20 13:42

          nosurf 是 Go 語言的一個 CSRF 跨站請求偽造(Cross Site Request Forgery) 中間件,可嵌入到 net/http 中使用,可方便與 GorillaMartini 框架結合使用。

          示例代碼:

          package main
          
          import (
              "fmt"
              "github.com/justinas/nosurf"
              "html/template"
              "net/http"
          )
          
          var templateString string = `
          <!doctype html>
          <html>
          <body>
          {{ if .name }}
          <p>Your name: {{ .name }}</p>
          {{ end }}
          <form action="/" method="POST">
          <input type="text" name="name">
          
          <!-- Try removing this or changing its value
               and see what happens -->
          <input type="hidden" name="csrf_token" value="{{ .token }}">
          <input type="submit" value="Send">
          </form>
          </body>
          </html>
          `
          var templ = template.Must(template.New("t1").Parse(templateString))
          
          func myFunc(w http.ResponseWriter, r *http.Request) {
              context := make(map[string]string)
              context["token"] = nosurf.Token(r)
              if r.Method == "POST" {
                  context["name"] = r.FormValue("name")
              }
          
              templ.Execute(w, context)
          }
          
          func main() {
              myHandler := http.HandlerFunc(myFunc)
              fmt.Println("Listening on http://127.0.0.1:8000/")
              http.ListenAndServe(":8000", nosurf.New(myHandler))
          }
          瀏覽 23
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  天天干夜夜操 | 四虎亚洲影院 | 超碰在线最新 | 青青草视频成人动漫视频 | 97超碰大香蕉 |