httpservice

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrorCodeInvalidRequest error code for invalid http request.
	ErrorCodeInvalidRequest = "invalid_request"

	// ErrorCodeValidationFailed error code for validation fails on http request payload.
	ErrorCodeValidationFailed = "validation_failed"

	// ErrorCodeInternalServerError error code for internal server error.
	ErrorCodeInternalServerError = "internal_server_error"
)

Variables

This section is empty.

Functions

func NewAppError

func NewAppError(code string, message string) error

NewAppError creates and returns a new app error with provided code and message.

func NewAppErrorWithCause

func NewAppErrorWithCause(code string, message string, cause error) error

NewAppErrorWithCause creates and returns a new app error with cause.

func Run

func Run(applicationconfig *applicationconfig.ApplicationConfig) error

Run starts the http server.

Types

type AppError

type AppError struct {
	// contains filtered or unexported fields
}

AppError represents the application error. Error of this type should be used in case when client needs to be informed with the failure details.

func (*AppError) Error

func (a *AppError) Error() string

type ErrorResponse

type ErrorResponse struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message"`
}

ErrorResponse represents the response payload of an app error.

type LoginHandler

type LoginHandler struct {
	// contains filtered or unexported fields
}

LoginHandler represents http handler for serving user login actions.

func NewLoginHandler

func NewLoginHandler(authService auth.Service, githubService github.Service, userService user.Service, clientURL string) *LoginHandler

NewLoginHandler creates and returns a new login handler.

func (*LoginHandler) GithubLogin

func (l *LoginHandler) GithubLogin(c *gin.Context)

GithubLogin initiates oauth2 login flow with github provider.

func (*LoginHandler) GithubOAuth2Callback

func (l *LoginHandler) GithubOAuth2Callback(c *gin.Context)

GithubOAuth2Callback processes github oauth2 callback. It validates the state, fetch token and user from github, stores the user to db, generates app token. The app token will be sent as token cookie with a redirect to client url.

func (*LoginHandler) TokenPayload

func (l *LoginHandler) TokenPayload(c *gin.Context)

TokenPayload reads the token from request cookie and sends it as response payload. The idea is to use header based jwt auth (instead of cookie based auth) to avoid any security issues.

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

Middleware represents a http middleware used primarily for authorization.

func NewMiddleware

func NewMiddleware(authService auth.Service) *Middleware

NewMiddleware creates and return the middleware.

func (*Middleware) AuthorizeToken

func (m *Middleware) AuthorizeToken() gin.HandlerFunc

AuthorizeToken retrieves and validates app token from authorization header of http request.

type NoteHandler

type NoteHandler struct {
	// contains filtered or unexported fields
}

NoteHandler represents http handler for managing note entities.

func NewNoteHandler

func NewNoteHandler(githubService github.Service, userService user.Service) *NoteHandler

NewNoteHandler creates and returns a new note handler.

func (*NoteHandler) DeleteNote

func (n *NoteHandler) DeleteNote(c *gin.Context)

DeleteNote deletes a note with requested path.

func (*NoteHandler) GetAllNotes

func (n *NoteHandler) GetAllNotes(c *gin.Context)

GetAllNotes returns all the notes from a path as a http response.

func (*NoteHandler) GetNote

func (n *NoteHandler) GetNote(c *gin.Context)

GetNote returns a note with requested path as a http response.

func (*NoteHandler) GetNotesTree

func (n *NoteHandler) GetNotesTree(c *gin.Context)

GetNotesTree returns a complete tree of note repository as a http response.

func (*NoteHandler) SaveNote

func (n *NoteHandler) SaveNote(c *gin.Context)

SaveNote stores the note and returns the metadata as a http response.

func (*NoteHandler) SearchNotes

func (n *NoteHandler) SearchNotes(c *gin.Context)

SearchNotes performs a note search operation with specified filter criteria. It returns the result of search operation as a http response.

type NoteRequestPayload

type NoteRequestPayload struct {
	SHA     string `json:"sha"`
	Content string `json:"content"`
}

NoteRequestPayload represents the http request payload of note entity.

type NoteResponsePayload

type NoteResponsePayload struct {
	SHA     string `json:"sha"`
	Path    string `json:"path"`
	Content string `json:"content"`
	Size    int    `json:"size"`
	IsDir   bool   `json:"is_dir"`
}

NoteResponsePayload represents the http response payload of note entity.

type NoteSearchResponsePayload

type NoteSearchResponsePayload struct {
	Total int                   `json:"total"`
	Notes []NoteResponsePayload `json:"notes"`
}

NoteSearchResponsePayload represents the http response payload for note search operation. Total is the count of total results found. Notes are the subset of search result as requested with pagination attributes.

type PreferenceHandler

type PreferenceHandler struct {
	// contains filtered or unexported fields
}

PreferenceHandler represents http handler for managing user preferences.

func NewPreferenceHandler

func NewPreferenceHandler(preferenceService preference.Service, githubService github.Service, userService user.Service) *PreferenceHandler

NewPreferenceHandler creates and returns a new preference handler.

func (*PreferenceHandler) AutoSetupRepo

func (p *PreferenceHandler) AutoSetupRepo(c *gin.Context)

AutoSetupRepo creates a new notes repo in user's github account and stores it as user's default repo preference.

func (*PreferenceHandler) GetRepos

func (p *PreferenceHandler) GetRepos(c *gin.Context)

GetRepos returns user repositories of logged in user.

func (*PreferenceHandler) SaveDefaultRepo

func (p *PreferenceHandler) SaveDefaultRepo(c *gin.Context)

SaveDefaultRepo stores the requested repo as user's default repo.

type RepoPayload

type RepoPayload struct {
	Name          string `json:"name"`
	Visibility    string `json:"visibility"`
	DefaultBranch string `json:"default_branch"`
}

RepoPayload represents the http request/response payload of repository entity.

func (RepoPayload) Validate

func (r RepoPayload) Validate() error

Validate validates the repo http request payload.

type UserHandler

type UserHandler struct {
	// contains filtered or unexported fields
}

UserHandler represents http handler for managing user entities.

func NewUserHandler

func NewUserHandler(userService user.Service) *UserHandler

NewUserHandler creates and returns a new user handler.

func (*UserHandler) Profile

func (u *UserHandler) Profile(c *gin.Context)

Profile returns the user profile as a http response.

type UserResponsePayload

type UserResponsePayload struct {
	Email       string       `json:"email"`
	Name        string       `json:"name,omitempty"`
	Location    string       `json:"location,omitempty"`
	AvatarURL   string       `json:"avatar_url,omitempty"`
	DisabledAt  *time.Time   `json:"disabled_at,omitempty"`
	DefaultRepo *RepoPayload `json:"default_repo,omitempty"`
}

UserResponsePayload represents the http response payload of user entity.

Jump to

Keyboard shortcuts

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