context

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const DocURL = "https://github.com/gogs/docs-api"

FIXME: move this constant to github.com/gogs/go-gogs-client

Variables

This section is empty.

Functions

func APIContexter

func APIContexter() macaron.Handler

func AuthenticateByToken added in v0.13.0

func AuthenticateByToken(ctx context.Context, token string) (*db.User, error)

AuthenticateByToken attempts to authenticate a user by the given access token. It returns db.ErrAccessTokenNotExist when the access token does not exist.

func Contexter

func Contexter() macaron.Handler

Contexter initializes a classic context for a request.

func GitHookService

func GitHookService() macaron.Handler

GitHookService checks if repository Git hooks service has been enabled.

func HandleOrgAssignment

func HandleOrgAssignment(c *Context, args ...bool)

func InjectParamsUser

func InjectParamsUser() macaron.Handler

InjectParamsUser returns a handler that retrieves target user based on URL parameter ':username', and injects it as *ParamsUser.

func OrgAssignment

func OrgAssignment(args ...bool) macaron.Handler

func RepoAssignment

func RepoAssignment(pages ...bool) macaron.Handler

[0]: issues, [1]: wiki

func RepoRef

func RepoRef() macaron.Handler

RepoRef handles repository reference name including those contain `/`.

func RequireRepoAdmin

func RequireRepoAdmin() macaron.Handler

func RequireRepoWriter

func RequireRepoWriter() macaron.Handler

func ServeGoGet added in v0.12.2

func ServeGoGet() macaron.Handler

ServeGoGet does quick responses for appropriate go-get meta with status OK regardless of whether the user has access to the repository, or the repository does exist at all. This is particular a workaround for "go get" command which does not respect .netrc file.

func Toggle

func Toggle(options *ToggleOptions) macaron.Handler

Types

type APIContext

type APIContext struct {
	*Context // TODO: Reduce to only needed fields instead of full shadow

	// Base URL for the version of API endpoints, e.g. https://try.gogs.io/api/v1
	BaseURL string

	Org *APIOrganization
}

func (*APIContext) Error

func (c *APIContext) Error(err error, msg string)

Error renders the 500 response.

func (*APIContext) ErrorStatus

func (c *APIContext) ErrorStatus(status int, err error)

ErrorStatus renders error with given status code.

func (*APIContext) Errorf

func (c *APIContext) Errorf(err error, format string, args ...any)

Errorf renders the 500 response with formatted message.

func (*APIContext) NoContent

func (c *APIContext) NoContent()

NoContent renders the 204 response.

func (*APIContext) NotFound

func (c *APIContext) NotFound()

NotFound renders the 404 response.

func (*APIContext) NotFoundOrError

func (c *APIContext) NotFoundOrError(err error, msg string)

NotFoundOrError use error check function to determine if the error is about not found. It responses with 404 status code for not found error, or error context description for logging purpose of 500 server error.

func (*APIContext) SetLinkHeader

func (c *APIContext) SetLinkHeader(total, pageSize int)

SetLinkHeader sets pagination link header by given total number and page size.

type APIOrganization

type APIOrganization struct {
	Organization *db.User
	Team         *db.Team
}

type Context

type Context struct {
	*macaron.Context
	Cache cache.Cache

	Flash   *session.Flash
	Session session.Store

	Link        string // Current request URL
	User        *db.User
	IsLogged    bool
	IsBasicAuth bool
	IsTokenAuth bool

	Repo *Repository
	Org  *Organization
	// contains filtered or unexported fields
}

Context represents context of a request.

func (*Context) Error

func (c *Context) Error(err error, msg string)

Error renders the 500 page.

func (*Context) Errorf

func (c *Context) Errorf(err error, format string, args ...any)

Errorf renders the 500 response with formatted message.

func (*Context) FormErr

func (c *Context) FormErr(names ...string)

FormErr sets "Err_xxx" field in template data.

func (*Context) GetErrMsg

func (c *Context) GetErrMsg() string

func (*Context) HTML

func (c *Context) HTML(status int, name string)

HTML responses template with given status.

func (*Context) HasApiError

func (c *Context) HasApiError() bool

HasError returns true if error occurs in form validation.

func (*Context) HasError

func (c *Context) HasError() bool

HasError returns true if error occurs in form validation.

func (*Context) HasValue

func (c *Context) HasValue(name string) bool

HasValue returns true if value of given name exists.

func (*Context) JSONSuccess

func (c *Context) JSONSuccess(data any)

JSONSuccess responses JSON with status http.StatusOK.

func (*Context) NotFound

func (c *Context) NotFound()

NotFound renders the 404 page.

func (*Context) NotFoundOrError

func (c *Context) NotFoundOrError(err error, msg string)

NotFoundOrError responses with 404 page for not found error and 500 page otherwise.

func (*Context) NotFoundOrErrorf

func (c *Context) NotFoundOrErrorf(err error, format string, args ...any)

NotFoundOrErrorf is same as NotFoundOrError but with formatted message.

func (*Context) PageIs

func (c *Context) PageIs(name string)

PageIs sets "PageIsxxx" field in template data.

func (*Context) PlainText

func (c *Context) PlainText(status int, msg string)

func (*Context) RawRedirect

func (c *Context) RawRedirect(location string, status ...int)

RawRedirect simply calls underlying Redirect method with no escape.

func (*Context) RawTitle

func (c *Context) RawTitle(title string)

RawTitle sets the "Title" field in template data.

func (*Context) Redirect

func (c *Context) Redirect(location string, status ...int)

Redirect responses redirection with given location and status. It escapes special characters in the location string.

func (*Context) RedirectSubpath

func (c *Context) RedirectSubpath(location string, status ...int)

RedirectSubpath responses redirection with given location and status. It prepends setting.Server.Subpath to the location string.

func (*Context) RenderWithErr

func (c *Context) RenderWithErr(msg, tpl string, f any)

RenderWithErr used for page has form validation but need to prompt error to users.

func (*Context) Require

func (c *Context) Require(name string)

Require sets "Requirexxx" field in template data.

func (*Context) RequireAutosize

func (c *Context) RequireAutosize()

func (*Context) RequireDropzone

func (c *Context) RequireDropzone()

func (*Context) RequireHighlightJS

func (c *Context) RequireHighlightJS()

func (*Context) RequireSimpleMDE

func (c *Context) RequireSimpleMDE()

func (*Context) ServeContent

func (c *Context) ServeContent(name string, r io.ReadSeeker, params ...any)

func (*Context) Success

func (c *Context) Success(name string)

Success responses template with status http.StatusOK.

func (*Context) Title

func (c *Context) Title(locale string)

Title localizes the "Title" field in template data.

func (*Context) UserID

func (c *Context) UserID() int64

UserID returns ID of current logged in user. It returns 0 if visitor is anonymous.

type Organization

type Organization struct {
	IsOwner      bool
	IsMember     bool
	IsTeamMember bool // Is member of team.
	IsTeamAdmin  bool // In owner team or team that has admin permission level.
	Organization *db.User
	OrgLink      string

	Team *db.Team
}

type ParamsUser

type ParamsUser struct {
	*db.User
}

ParamsUser is the wrapper type of the target user defined by URL parameter, namely ':username'.

type PullRequest

type PullRequest struct {
	BaseRepo *db.Repository
	Allowed  bool
	SameRepo bool
	HeadInfo string // [<user>:]<branch>
}

type Repository

type Repository struct {
	AccessMode   db.AccessMode
	IsWatching   bool
	IsViewBranch bool
	IsViewTag    bool
	IsViewCommit bool
	Repository   *db.Repository
	Owner        *db.User
	Commit       *git.Commit
	Tag          *git.Tag
	GitRepo      *git.Repository
	BranchName   string
	TagName      string
	TreePath     string
	CommitID     string
	RepoLink     string
	CloneLink    repoutil.CloneLink
	CommitsCount int64
	Mirror       *db.Mirror

	PullRequest *PullRequest
}

func (*Repository) CanEnableEditor

func (r *Repository) CanEnableEditor() bool

CanEnableEditor returns true if repository is editable and user has proper access level.

func (*Repository) Editorconfig

func (r *Repository) Editorconfig() (*editorconfig.Editorconfig, error)

Editorconfig returns the ".editorconfig" definition if found in the HEAD of the default branch.

func (*Repository) HasAccess

func (r *Repository) HasAccess() bool

HasAccess returns true if the current user has at least read access for this repository

func (*Repository) IsAdmin

func (r *Repository) IsAdmin() bool

IsAdmin returns true if current user has admin or higher access of repository.

func (*Repository) IsOwner

func (r *Repository) IsOwner() bool

IsOwner returns true if current user is the owner of repository.

func (*Repository) IsWriter

func (r *Repository) IsWriter() bool

IsWriter returns true if current user has write or higher access of repository.

func (*Repository) MakeURL

func (r *Repository) MakeURL(location any) string

MakeURL accepts a string or url.URL as argument and returns escaped URL prepended with repository URL.

func (*Repository) PullRequestURL

func (r *Repository) PullRequestURL(baseBranch, headBranch string) string

PullRequestURL returns URL for composing a pull request. This function does not check if the repository can actually compose a pull request.

type ToggleOptions

type ToggleOptions struct {
	SignInRequired  bool
	SignOutRequired bool
	AdminRequired   bool
	DisableCSRF     bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL