{"modulePath":"github.com/batnoter/batnoter-api","version":"v1.0.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpservice\n\n## Constants\n\n```go\nconst (\n\t// ErrorCodeInvalidRequest error code for invalid http request.\n\tErrorCodeInvalidRequest = \"invalid_request\"\n\n\t// ErrorCodeValidationFailed error code for validation fails on http request payload.\n\tErrorCodeValidationFailed = \"validation_failed\"\n\n\t// ErrorCodeInternalServerError error code for internal server error.\n\tErrorCodeInternalServerError = \"internal_server_error\"\n)\n```\n\n## Functions\n\n```go\nfunc NewAppError(code string, message string) error\n```\nNewAppError creates and returns a new app error with provided code and message.\n\n```go\nfunc NewAppErrorWithCause(code string, message string, cause error) error\n```\nNewAppErrorWithCause creates and returns a new app error with cause.\n\n```go\nfunc Run(applicationconfig *applicationconfig.ApplicationConfig) error\n```\nRun starts the http server.\n\n## Types\n\n```go\ntype AppError struct {\n\t// contains filtered or unexported fields\n}\n```\nAppError represents the application error. Error of this type should be used in case when client needs to be informed with the failure details.\n\n```go\nfunc (a *AppError) Error() string\n```\n\n```go\ntype ErrorResponse struct {\n\tCode    string `json:\"code,omitempty\"`\n\tMessage string `json:\"message\"`\n}\n```\nErrorResponse represents the response payload of an app error.\n\n```go\ntype LoginHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nLoginHandler represents http handler for serving user login actions.\n\n```go\nfunc NewLoginHandler(authService auth.Service, githubService github.Service, userService user.Service, clientURL string) *LoginHandler\n```\nNewLoginHandler creates and returns a new login handler.\n\n```go\nfunc (l *LoginHandler) GithubLogin(c *gin.Context)\n```\nGithubLogin initiates oauth2 login flow with github provider.\n\n```go\nfunc (l *LoginHandler) GithubOAuth2Callback(c *gin.Context)\n```\nGithubOAuth2Callback 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.\n\n```go\nfunc (l *LoginHandler) TokenPayload(c *gin.Context)\n```\nTokenPayload 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.\n\n```go\ntype Middleware struct {\n\t// contains filtered or unexported fields\n}\n```\nMiddleware represents a http middleware used primarily for authorization.\n\n```go\nfunc NewMiddleware(authService auth.Service) *Middleware\n```\nNewMiddleware creates and return the middleware.\n\n```go\nfunc (m *Middleware) AuthorizeToken() gin.HandlerFunc\n```\nAuthorizeToken retrieves and validates app token from authorization header of http request.\n\n```go\ntype NoteHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nNoteHandler represents http handler for managing note entities.\n\n```go\nfunc NewNoteHandler(githubService github.Service, userService user.Service) *NoteHandler\n```\nNewNoteHandler creates and returns a new note handler.\n\n```go\nfunc (n *NoteHandler) DeleteNote(c *gin.Context)\n```\nDeleteNote deletes a note with requested path.\n\n```go\nfunc (n *NoteHandler) GetAllNotes(c *gin.Context)\n```\nGetAllNotes returns all the notes from a path as a http response.\n\n```go\nfunc (n *NoteHandler) GetNote(c *gin.Context)\n```\nGetNote returns a note with requested path as a http response.\n\n```go\nfunc (n *NoteHandler) GetNotesTree(c *gin.Context)\n```\nGetNotesTree returns a complete tree of note repository as a http response.\n\n```go\nfunc (n *NoteHandler) SaveNote(c *gin.Context)\n```\nSaveNote stores the note and returns the metadata as a http response.\n\n```go\nfunc (n *NoteHandler) SearchNotes(c *gin.Context)\n```\nSearchNotes performs a note search operation with specified filter criteria. It returns the result of search operation as a http response.\n\n```go\ntype NoteRequestPayload struct {\n\tSHA     string `json:\"sha\"`\n\tContent string `json:\"content\"`\n}\n```\nNoteRequestPayload represents the http request payload of note entity.\n\n```go\ntype NoteResponsePayload struct {\n\tSHA     string `json:\"sha\"`\n\tPath    string `json:\"path\"`\n\tContent string `json:\"content\"`\n\tSize    int    `json:\"size\"`\n\tIsDir   bool   `json:\"is_dir\"`\n}\n```\nNoteResponsePayload represents the http response payload of note entity.\n\n```go\ntype NoteSearchResponsePayload struct {\n\tTotal int                   `json:\"total\"`\n\tNotes []NoteResponsePayload `json:\"notes\"`\n}\n```\nNoteSearchResponsePayload 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.\n\n```go\ntype PreferenceHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nPreferenceHandler represents http handler for managing user preferences.\n\n```go\nfunc NewPreferenceHandler(preferenceService preference.Service, githubService github.Service, userService user.Service) *PreferenceHandler\n```\nNewPreferenceHandler creates and returns a new preference handler.\n\n```go\nfunc (p *PreferenceHandler) AutoSetupRepo(c *gin.Context)\n```\nAutoSetupRepo creates a new notes repo in user's github account and stores it as user's default repo preference.\n\n```go\nfunc (p *PreferenceHandler) GetRepos(c *gin.Context)\n```\nGetRepos returns user repositories of logged in user.\n\n```go\nfunc (p *PreferenceHandler) SaveDefaultRepo(c *gin.Context)\n```\nSaveDefaultRepo stores the requested repo as user's default repo.\n\n```go\ntype RepoPayload struct {\n\tName          string `json:\"name\"`\n\tVisibility    string `json:\"visibility\"`\n\tDefaultBranch string `json:\"default_branch\"`\n}\n```\nRepoPayload represents the http request/response payload of repository entity.\n\n```go\nfunc (r RepoPayload) Validate() error\n```\nValidate validates the repo http request payload.\n\n```go\ntype UserHandler struct {\n\t// contains filtered or unexported fields\n}\n```\nUserHandler represents http handler for managing user entities.\n\n```go\nfunc NewUserHandler(userService user.Service) *UserHandler\n```\nNewUserHandler creates and returns a new user handler.\n\n```go\nfunc (u *UserHandler) Profile(c *gin.Context)\n```\nProfile returns the user profile as a http response.\n\n```go\ntype UserResponsePayload struct {\n\tEmail       string       `json:\"email\"`\n\tName        string       `json:\"name,omitempty\"`\n\tLocation    string       `json:\"location,omitempty\"`\n\tAvatarURL   string       `json:\"avatar_url,omitempty\"`\n\tDisabledAt  *time.Time   `json:\"disabled_at,omitempty\"`\n\tDefaultRepo *RepoPayload `json:\"default_repo,omitempty\"`\n}\n```\nUserResponsePayload represents the http response payload of user entity.\n\n","path":"github.com/batnoter/batnoter-api/internal/httpservice","name":"httpservice","synopsis":"","isRedistributable":true}
