久久精品中文字幕一区,日韩久久一区二区,久久精彩视频http://www.aygfsteel.com/willpower88/category/55345.html對JAVA有點理解了……zh-cnWed, 07 Feb 2024 01:39:26 GMTWed, 07 Feb 2024 01:39:26 GMT60gland debug. Got a connection, launched process http://www.aygfsteel.com/willpower88/archive/2024/02/04/451359.html一凡一凡Sun, 04 Feb 2024 05:57:00 GMThttp://www.aygfsteel.com/willpower88/archive/2024/02/04/451359.htmlhttp://www.aygfsteel.com/willpower88/comments/451359.htmlhttp://www.aygfsteel.com/willpower88/archive/2024/02/04/451359.html#Feedback0http://www.aygfsteel.com/willpower88/comments/commentRss/451359.htmlhttp://www.aygfsteel.com/willpower88/services/trackbacks/451359.html解決辦法,重新安裝xcode  
rm -rf /Library/Developer/CommandLineTools
xcode
-select --install


一凡 2024-02-04 13:57 發表評論
]]>
gin跨域http://www.aygfsteel.com/willpower88/archive/2019/12/26/434991.html一凡一凡Thu, 26 Dec 2019 03:17:00 GMThttp://www.aygfsteel.com/willpower88/archive/2019/12/26/434991.htmlhttp://www.aygfsteel.com/willpower88/comments/434991.htmlhttp://www.aygfsteel.com/willpower88/archive/2019/12/26/434991.html#Feedback0http://www.aygfsteel.com/willpower88/comments/commentRss/434991.htmlhttp://www.aygfsteel.com/willpower88/services/trackbacks/434991.html
  • 新增中間件cors
  • func Cors() gin.HandlerFunc {
    return func(c *gin.Context) {
    method := c.Request.Method

    c.Header("Access-Control-Allow-Origin", "*") //必選
         c.Header("Access-Control-Allow-Headers", "*") //可選 如果request有header, 必選
         //c.Header("Access-Control-Allow-Credentials", "true") //可選
    //c.Header("Access-Control-Allow-Methods", "*") //可選
    //c.Header("Access-Control-Expose-Headers", "*") //可選

    //放行所有OPTIONS方法
    if method == "OPTIONS" {
    c.AbortWithStatus(http.StatusOK)
    }
    // 處理請求
    c.Next()
    }
    }
  • 在router里增加cors,必須在group之前,全局設置
    r.Use(gin.Logger(), gin.Recovery(), cors.Cors())
  • 測試代碼,header設置不能多于cors設置
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    </head>
    <link type="test/css" href="css/style.css" rel="stylesheet">
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script type="text/javascript">
    $(function(){
    $("#cors").click(
    function(){
    $.ajax({
    headers:{
    "Content-Type":"application/json;charset=UTF-8",
    "Access":"adsad",
    "Access-Token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJwYXNzd29yZCI6InRlc3QxMjM0NTYiLCJleHAiOjE1NzczMzY3MTIsImlzcyI6Imdpbi1ibG9nIn0.wMlQXqZO2V0LR-FIgDh45LWI0OYMYi6an_NvRmF0Nug"
    },
    url:"http://127.0.0.1:8000/api/v1/articles",
    success:function(data){
    console.log("start");
    console.log(data);
    }
    })
    });
    });
    </script>
    <body>
    <input type="button" id="cors" value="core跨域測試">
    </body>
    </html>
  • 請求的headers數量、名稱與cors里的設置需要嚴格對應,不然報錯如下
    Access to XMLHttpRequest at 'http://127.0.0.1:8000/api/v1/articles' from origin 'http://localhost:9999' has been blocked by CORS policy: Request header field access is not allowed by Access-Control-Allow-Headers in preflight response.


  • 一凡 2019-12-26 11:17 發表評論
    ]]>
    gin-swagger鑒權(auth)http://www.aygfsteel.com/willpower88/archive/2019/12/23/434981.html一凡一凡Mon, 23 Dec 2019 08:08:00 GMThttp://www.aygfsteel.com/willpower88/archive/2019/12/23/434981.htmlhttp://www.aygfsteel.com/willpower88/comments/434981.htmlhttp://www.aygfsteel.com/willpower88/archive/2019/12/23/434981.html#Feedback0http://www.aygfsteel.com/willpower88/comments/commentRss/434981.htmlhttp://www.aygfsteel.com/willpower88/services/trackbacks/434981.htmlin header 說明參數放在header,你的鑒權代碼需要從header中獲取

    // @title gin-blog API
    // @version 0.0.1
    // @description This is a gin blog example
    // @securityDefinitions.apikey ApiKeyAuth
    // @in header
    // @name token
    // @BasePath /

    2、在具體的handler里添加如下注釋,此處的ApiKeyAuth和main中的apike對應,切記不要修改
    // @Security ApiKeyAuth

    3、swagger頁面如下:


    4、添加token后,后續所有有鑒權接口的header里自動攜帶token


    一凡 2019-12-23 16:08 發表評論
    ]]>
    主站蜘蛛池模板: 福州市| 苏尼特右旗| 社旗县| 瓮安县| 句容市| 乌恰县| 环江| 高平市| 泽普县| 无棣县| 兴城市| 宝兴县| 柘荣县| 雷波县| 高青县| 亚东县| 集贤县| 泸定县| 五原县| 金湖县| 西华县| 饶阳县| 垫江县| 同仁县| 彰武县| 明水县| 泉州市| 长海县| 建湖县| 军事| 万全县| 长岭县| 奎屯市| 黑水县| 抚州市| 商南县| 商丘市| 内黄县| 四子王旗| 涿州市| 上思县|