gin/araneae_response.go
Muyao CHEN 116d0b112e
Some checks are pending
CodeQL / Analyze (go) (push) Waiting to run
Run Tests / lint (push) Waiting to run
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.21, ~/.cache/go-build, ubuntu-latest, ) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.21, ~/.cache/go-build, ubuntu-latest, -race) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.21, ~/.cache/go-build, ubuntu-latest, -tags "sonic avx") (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.21, ~/.cache/go-build, ubuntu-latest, -tags go_json) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.21, ~/.cache/go-build, ubuntu-latest, -tags nomsgpack) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.21, ~/Library/Caches/go-build, macos-latest, ) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.21, ~/Library/Caches/go-build, macos-latest, -race) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.21, ~/Library/Caches/go-build, macos-latest, -tags "sonic avx") (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.21, ~/Library/Caches/go-build, macos-latest, -tags go_json) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.21, ~/Library/Caches/go-build, macos-latest, -tags nomsgpack) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.22, ~/.cache/go-build, ubuntu-latest, ) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.22, ~/.cache/go-build, ubuntu-latest, -race) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.22, ~/.cache/go-build, ubuntu-latest, -tags "sonic avx") (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.22, ~/.cache/go-build, ubuntu-latest, -tags go_json) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.22, ~/.cache/go-build, ubuntu-latest, -tags nomsgpack) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.22, ~/Library/Caches/go-build, macos-latest, ) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.22, ~/Library/Caches/go-build, macos-latest, -race) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.22, ~/Library/Caches/go-build, macos-latest, -tags "sonic avx") (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.22, ~/Library/Caches/go-build, macos-latest, -tags go_json) (push) Blocked by required conditions
Run Tests / ${{ matrix.os }} @ Go ${{ matrix.go }} ${{ matrix.test-tags }} (1.22, ~/Library/Caches/go-build, macos-latest, -tags nomsgpack) (push) Blocked by required conditions
Araneae: integrate custom context interfaces into Gin
2024-09-28 10:22:47 +02:00

79 lines
1.6 KiB
Go

package gin
import (
"net/http"
)
type IResponse interface {
IJSON(status int, obj any) IResponse
IXML(status int, obj any) IResponse
IHTML(status int, filepath string, obj any) IResponse
IText(status int, format string, values ...any) IResponse
IRedirect(status int, path string) IResponse
ISetHeader(key string, val string) IResponse
ISetCookie(
key string,
val string,
maxAge int,
path, domain string,
secure, httpOnly bool,
) IResponse
ISetStatus(code int) IResponse
// set 200
ISetOKStatus() IResponse
}
func (ctx *Context) IJSON(status int, obj any) IResponse {
ctx.JSON(status, obj)
return ctx
}
func (ctx *Context) IXML(status int, obj any) IResponse {
ctx.XML(status, obj)
return ctx
}
func (ctx *Context) IHTML(status int, filepath string, obj any) IResponse {
ctx.HTML(status, filepath, obj)
return ctx
}
func (ctx *Context) IText(status int, format string, values ...any) IResponse {
ctx.String(status, format, values...)
return ctx
}
func (ctx *Context) IRedirect(status int, path string) IResponse {
ctx.Redirect(status, path)
return ctx
}
func (ctx *Context) ISetHeader(key string, val string) IResponse {
ctx.Header(key, val)
return ctx
}
func (ctx *Context) ISetCookie(
key string,
val string,
maxAge int,
path, domain string,
secure, httpOnly bool,
) IResponse {
ctx.SetCookie(key, val, maxAge, path, domain, secure, httpOnly)
return ctx
}
func (ctx *Context) ISetStatus(code int) IResponse {
ctx.Status(code)
return ctx
}
// set 200
func (ctx *Context) ISetOKStatus() IResponse {
ctx.Status(http.StatusOK)
return ctx
}