Giter Site home page Giter Site logo

golang's Introduction

context 上下文:
https://blog.golang.org/context

context不仅可以控制并发逻辑,而且本身也可以携带变量,类似于Map。并且提供Value方法用于获取指定Key的Value值.
context包,可以轻松地将请求范围的值,取消信号以及截止时间跨越API边界传递到处理请求所涉及的所有参数
Context之间是具有父子关系的,新的Context往往从已有的Context中创建, 因此,最终所有的context组成一颗树状的结构.
context包中提供一个创建初始Context的方法: func Background() ContextBackgraund就是所有context树的根。
WithCancel和WithTimeout两个方法用于在已有的context上创建新的context,同时从新的context中可以获取到旧的context中保存的Key,Value

context可以被多个并发的Goroutine使用,对context的访问是并发安全的

c.Abort()只是设置了一些内部标志,标志着上下文以某种方式表明异常终止。 但是在后续中间件中可以根据Isabort() 判断,从而进行 C.Json(500,"") 返回一些error信息

gin 从panic中恢复: 加middleware避免的panic导致的进程中止 RecoveryWithWriter returns a middleware for a given writer that recovers from any panics and writes a 500 if there was one.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.