您当前的位置: 首页 >  json

衣舞晨风

暂无认证

  • 9浏览

    0关注

    1156博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Golang通过JSONP设置localstorage

衣舞晨风 发布时间:2022-09-05 22:45:00 ,浏览量:9

package localstorage

import (
	"bytes"
	"log"
	"text/template"
)

const authPageTemplate = `



    auth
    
        /* loading */
        .jiankunking_loading-wrp {
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
        }

        .jiankunking_loading-wrp .jiankunking_loading-box {
            padding: 98px;
            display: flex;
            justify-content: center;
            align-items: center
        }

        .jiankunking_loading-dot {
            animation: jiankunking_loading-rotate 1.2s infinite linear;
            transform: rotate(45deg);
            position: relative;
            display: inline-block;
            font-size: 32px;
            width: 32px;
            height: 32px;
            box-sizing: border-box
        }

        .jiankunking_loading-dot i {
            width: 14px;
            height: 14px;
            position: absolute;
            display: block;
            background-color: #1890ff;
            border-radius: 100%;
            transform: scale(.75);
            transform-origin: 50% 50%;
            opacity: .3;
            animation: jiankunking_loading-spin-move 1s infinite linear alternate
        }

        .jiankunking_loading-dot i:nth-child(1) {
            top: 0;
            left: 0
        }

        .jiankunking_loading-dot i:nth-child(2) {
            top: 0;
            right: 0;
            -webkit-animation-delay: .4s;
            animation-delay: .4s
        }

        .jiankunking_loading-dot i:nth-child(3) {
            right: 0;
            bottom: 0;
            -webkit-animation-delay: .8s;
            animation-delay: .8s
        }

        .jiankunking_loading-dot i:nth-child(4) {
            bottom: 0;
            left: 0;
            -webkit-animation-delay: 1.2s;
            animation-delay: 1.2s
        }

        @keyframes jiankunking_loading-rotate {
            to {
                -webkit-transform: rotate(405deg);
                transform: rotate(405deg)
            }
        }

        @-webkit-keyframes jiankunking_loading-rotate {
            to {
                -webkit-transform: rotate(405deg);
                transform: rotate(405deg)
            }
        }

        @keyframes jiankunking_loading-spin-move {
            to {
                opacity: 1
            }
        }

        @-webkit-keyframes jiankunking_loading-spin-move {
            to {
                opacity: 1
            }
        }
    



    
(function () { // 获取重定向地址 const redirectUrl = "{{ .RedirectUrl }}" || "/"; const token= "{{ .Token }}"; const tokenName = "{{ .TokenName }}"; localStorage.setItem(tokenName, token); location.href = redirectUrl })() ` type AuthPageParams struct { RedirectUrl string Token string TokenName string } func ExecAuthPageTemplate(params *AuthPageParams) string { t := template.Must(template.New("authPage").Parse(authPageTemplate)) var buf bytes.Buffer t.Execute(&buf, params) data := buf.String() log.Println(data) return data }

写入响应

func WriteHTML(w http.ResponseWriter, html string) error {
	w.Header().Set("Content-Type", "text/html")
	_, err := w.Write([]byte(html))
	return err
}

WriteHTML(ctx.Writer, localstorage.ExecAuthPageTemplate(&localstorage.AuthPageParams{
		RedirectUrl: redirectUri,
		Token:       token,
		TokenName:   'x_jwt',
	}))
关注
打赏
1647422595
查看更多评论
立即登录/注册

微信扫码登录

0.0517s