Skip to content

Latest commit

ย 

History

History
56 lines (44 loc) ยท 3.47 KB

fasthttp.md

File metadata and controls

56 lines (44 loc) ยท 3.47 KB

fasthttp

  • ํŒจํ‚ค์ง€ ์„ค์น˜ : go get github.com/valyala/fasthttp

  • document ์ž˜ ์ฐธ๊ณ ํ•ด์„œ ์›ํ•˜๋Š” ํ•จ์ˆ˜ ์ž˜ ํ™œ์šฉ ํ•  ๊ฒƒ.

    • ctx.Response.SetBody๋ž‘ ctx.Response WriteTo ๋‘˜๋‹ค ์‚ฌ์šฉํ•ด์„œ body๋ž‘ header๊ฐ€ ๋™์‹œ์— ๋ณด๋‚ด์กŒ์—ˆ์Œ
    • ํ•จ์ˆ˜ ๋™์ž‘์„ ์ž˜ ํ™•์ธํ•˜๊ณ  ์‚ฌ์šฉํ•ด์•ผ ๋จ
    • ctx.Response.SetBody
    • ctx.Response.WriteTo
    • SetBody vs SetBodyString ์„ฑ๋Šฅ ๋น„๊ต ๊ด€๋ จ issue #722

Do function

  • func Do(req * Request, resp * Response) error
    • ์ž…๋ ฅ๋ฐ›์€ request๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ณ , ํ•ด๋‹น request์— ๋Œ€ํ•œ response๋ฅผ ๋ฐ›์Œ.
    • ์ž…๋ ฅํ•  reqeust์—๋Š” ์ „์ฒด url์ด ํฌํ•จ๋˜์–ด์•ผํ•จ.
  • func DoDeadline(req * Request, resp * Response, deadline time.Time) error
    • Do ํ•จ์ˆ˜์˜ ๋™์ž‘ + ์ž…๋ ฅ๋ฐ›์€ deadline๊นŒ์ง€ response๋ฅผ ๊ธฐ๋‹ค๋ฆฌ๋Š” ํ•จ์ˆ˜.
  • func DoRedirects(req * Request, resp * Response, maxRedirectsCount int) error
    • Do ํ•จ์ˆ˜์˜ ๋™์ž‘ + maxRedirectsCount ๋ฆฌ๋””๋ ‰์…˜์— ๋”ฐ๋ผ ์ง€์ •๋œ response๋ฅผ ๋ฐ˜ํ™˜๋จ.
    • ๋ฆฌ๋””๋ ‰์…˜ ์ˆ˜๊ฐ€ ์ง€์ •ํ•œ maxRedirectsCount๋ฅผ ์ดˆ๊ณผํ•  ์‹œ, ErrTooManyRedirects(error) ๋ฐ˜ํ™˜๋จ.
  • func DoTimeout(req * Request, resp * Response, timeout time.Duration) error
    • Do ํ•จ์ˆ˜์˜ ๋™์ž‘ + ์ž…๋ ฅ๋ฐ›์€ timeout๊นŒ์ง€ response๋ฅผ ๊ธฐ๋‹ค๋ฆฌ๋Š” ํ•จ์ˆ˜.
    • ํ•ด๋‹น timeout๊นŒ์ง€ response๊ฐ€ ๋ฐ˜ํ™˜๋˜์ง€ ์•Š์œผ๋ฉด ErrTimeout(error)์ด ๋ฐ˜ํ™˜๋จ.

fasthttp.RquestCtx

  • ctx.QueryArgs().Peek()
    • (์˜ˆ) HTTP POST๋กœ http://localhost:8080/user?name=sujin ๊ณผ ๊ฐ™์ด ์ฟผ๋ฆฌ๋ฅผ ๋‚ ๋ฆด ๋•Œ, key(name)์— ํ•ด๋‹นํ•˜๋Š” value๋ฅผ ์ถ”์ถœํ•˜๋ ค๋ฉด?
    • ์ด๋•Œ ์‚ฌ์šฉ๋˜๋Š” ํ•จ์ˆ˜๋กœ, ์ฟผ๋ฆฌ์— ๋Œ€ํ•ด ํŠน์ • ํ‚ค ๊ฐ’์— ๋Œ€ํ•ด ์ž…๋ ฅํ•œ Value ๊ฐ’์„ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜
  • ctx.UserValue()
    • (์˜ˆ) HTTP GET์œผ๋กœ http://localhost:8080/user/{name}๊ณผ ๊ฐ™์ด ๋ผ์šฐํŒ… ์„ค์ •๋œ ์„œ๋ฒ„์— ๋Œ€ํ•ด http://localhost:8080/user/sujin ์œผ๋กœ ๊ฐ’์„ ์ž…๋ ฅํ•  ๋•Œ, ์ž…๋ ฅ๋œ ๊ฐ’์„ ์ถ”์ถœํ•˜๋ ค๋ฉด?
    • ์ด๋•Œ ์‚ฌ์šฉ๋˜๋Š” ํ•จ์ˆ˜๋กœ, ์‚ฌ์šฉ์ž๊ฐ€ HTTP GET Method๋ฅผ ํ†ตํ•ด ์ž…๋ ฅํ•œ ํŠน์ • ํ‚ค ๊ฐ’์— ๋Œ€ํ•ด value๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ํ•จ์ˆ˜

ErrorList

์ฐธ๊ณ