diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-05-08 17:36:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-08 17:36:54 +0800 |
commit | cb700aedd1e670fb47b8cf0cd67fb117a1ad88a2 (patch) | |
tree | 90cdc8e732b1c498bf5113accad8dc4245a059ac /modules/context/context_data.go | |
parent | ff5629268c5c01d3f460570baa571baef3f896cd (diff) | |
download | gitea-cb700aedd1e670fb47b8cf0cd67fb117a1ad88a2.tar.gz gitea-cb700aedd1e670fb47b8cf0cd67fb117a1ad88a2.zip |
Split "modules/context.go" to separate files (#24569)
The "modules/context.go" is too large to maintain.
This PR splits it to separate files, eg: context_request.go,
context_response.go, context_serve.go
This PR will help:
1. The future refactoring for Gitea's web context (eg: simplify the context)
2. Introduce proper "range request" support
3. Introduce context function
This PR only moves code, doesn't change any logic.
Diffstat (limited to 'modules/context/context_data.go')
-rw-r--r-- | modules/context/context_data.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/modules/context/context_data.go b/modules/context/context_data.go new file mode 100644 index 0000000000..cdf4ff9afe --- /dev/null +++ b/modules/context/context_data.go @@ -0,0 +1,43 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package context + +import "code.gitea.io/gitea/modules/web/middleware" + +// GetData returns the data +func (ctx *Context) GetData() middleware.ContextData { + return ctx.Data +} + +// HasAPIError returns true if error occurs in form validation. +func (ctx *Context) HasAPIError() bool { + hasErr, ok := ctx.Data["HasError"] + if !ok { + return false + } + return hasErr.(bool) +} + +// GetErrMsg returns error message +func (ctx *Context) GetErrMsg() string { + return ctx.Data["ErrorMsg"].(string) +} + +// HasError returns true if error occurs in form validation. +// Attention: this function changes ctx.Data and ctx.Flash +func (ctx *Context) HasError() bool { + hasErr, ok := ctx.Data["HasError"] + if !ok { + return false + } + ctx.Flash.ErrorMsg = ctx.Data["ErrorMsg"].(string) + ctx.Data["Flash"] = ctx.Flash + return hasErr.(bool) +} + +// HasValue returns true if value of given name exists. +func (ctx *Context) HasValue(name string) bool { + _, ok := ctx.Data[name] + return ok +} |