v1

package
v0.0.0-...-93660c8 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultRequestErrorHandler api.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
		w.Header().Set("Content-Type", "application/json")
		w.WriteHeader(http.StatusBadRequest)

		e := v1.Error{Type: v1.BadRequest, Description: err.Error()}
		if err := json.NewEncoder(w).Encode(e); err != nil {
			_, _ = fmt.Fprintf(w, "{\"type\":\"%s\",\"description\":\"%s\"}", v1.InternalError, "failed to serialize error")
		}
	}

	DefaultResponseErrorHandler api.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) {
		w.Header().Set("Content-Type", "application/json")

		var (
			status = http.StatusInternalServerError
			type_  = v1.InternalError

			httpErr *api.HTTPError
		)
		if errors.As(err, &httpErr) {
			status = httpErr.Status

			if httpErr.Type != "" {
				type_ = v1.ErrorType(httpErr.Type)
			}
		}

		w.WriteHeader(status)

		e := v1.Error{Type: type_, Description: err.Error()}
		if err := json.NewEncoder(w).Encode(e); err != nil {
			_, _ = fmt.Fprintf(w, "{\"type\":\"%s\",\"description\":\"%s\"}", v1.InternalError, "failed to serialize error")
		}
	}
)

Functions

func NewRouter

func NewRouter(handler v1.StrictServerInterface) http.Handler

NewRouter creates a new nero v1 API router.

Types

type Server

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

Server is a REST server for the nero v1 API.

func NewServer

func NewServer(repos []*repo.Repository, logger *zap.Logger) (*Server, error)

NewServer creates a new server with pre-defined repositories.

func (*Server) DeleteRepoId

func (*Server) PostRepo

func (*Server) Repos

func (s *Server) Repos() []*repo.Repository

Repos returns all repositories available to the server.

Jump to

Keyboard shortcuts

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