zoukankan      html  css  js  c++  java
  • go web 

    1.停掉一个http 服务

    (1.)取消context
    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
    defer cancel()
    (2.)执行shutdown()
    http.Server.Shutdown(ctx)
    

    2.启动一个http服务

    httpServer := &http.Server{
    	Addr:              fmt.Sprintf(":%d", p.httpPort),
    	Handler:           routers.Router,
    	ReadHeaderTimeout: 5 * time.Second,
    }
    
    httpServer.ListenAndServe()
    

    3.解析.ini文件

    // 先获取章节,再获取相应的字段,并赋值默认值
    *ini.File.Section("rtsp").Key("ffmpeg_path").MustString("")
    

    4.md5加密

    func MD5(str string) string {
    	encoder := md5.New()
    	encoder.Write([]byte(str))
    	return hex.EncodeToString(encoder.Sum(nil))
    }
    

    5.session token

    //创建token
    sess := sessions.Default(c)
    sess.Set("uid", user.ID)
    sess.Set("uname", user.Username)
    c.IndentedJSON(200, gin.H{
    	"token": sessions.Default(c).ID(),
    })
    
    //获取token
    sess := sessions.Default(c)
    uid := sess.Get("uid")
    if uid != nil {
    	c.IndentedJSON(200, gin.H{
    		"id":   uid,
    		"name": sess.Get("uname"),
    	})
    }
    
    //销毁session,退出登录
    sess := sessions.Default(c)
    sess.Destroy()
    
    //修改密码后,token要重新赋值
    sess := sessions.Default(c)
    token, _ := sess.RenewID()
    c.IndentedJSON(http.StatusOK, gin.H{
    	"token": token,
    })
    
  • 相关阅读:
    C++中的指针和数组
    windows系统下JDK1.6环境变量配置
    Java Reflection (JAVA反射)
    转载:cin深入分析(下) – cin的错误处理
    OpenGL总结
    OpenGL纹理
    c/C++内存分配
    转载:cin深入分析(上) – cin输入操作处理
    c++中string的用法
    OpenGL颜色
  • 原文地址:https://www.cnblogs.com/tomtellyou/p/12599550.html
Copyright © 2011-2022 走看看