httpserver

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultReadTimeout  = 2 * time.Hour
	DefaultWriteTimeout = 2 * time.Hour
	DefaultIdleTimeout  = 5 * time.Minute
)
View Source
const (
	DeepenFrom = "deepen-from" // shallow base
	Deepen     = "deepen"      // deepen <depth>
	Have       = "have"        // local have
)
View Source
const (
	ErrorMessageKey = "X-Zeta-Error-Message"
	JSON_MIME       = "application/json"
)
View Source
const (
	//
	IfNoneMatch = "If-None-Match"
	ETag        = "ETag"
	// Zeta HTTP Header
	AUTHORIZATION        = "Authorization"
	ZETA_PROTOCOL        = "Zeta-Protocol"
	ZETA_AUTHORIZATION   = "X-Zeta-Authorization"
	ZETA_COMMAND_OLDREV  = "X-Zeta-Command-OldRev"
	ZETA_COMMAND_NEWREV  = "X-Zeta-Command-NewRev"
	ZETA_TERMINAL        = "X-Zeta-Terminal"
	ZETA_OBJECTS_STATS   = "X-Zeta-Objects-Stats"
	ZETA_COMPRESSED_SIZE = "X-Zeta-Compressed-Size"
	// ZETA Protocol Content Type
	ZETA_MIME_BLOB          = "application/x-zeta-blob"
	ZETA_MIME_BLOBS         = "application/x-zeta-blobs"
	ZETA_MIME_MULTI_OBJECTS = "application/x-zeta-multi-objects"
	ZETA_MIME_MD            = "application/x-zeta-metadata"
	ZETA_MIME_COMPRESS_MD   = "application/x-zeta-compress-metadata"
	ZETA_MIME_REPORT_RESULT = "application/x-zeta-report-result"
	ZETA_MIME_VND_JSON      = "application/vnd.zeta+json"
	ZETA_MIME_FRAGMENTS_MD  = "application/vnd.zeta-fragments+json" // fragments json format
)
View Source
const (
	GeneralBranch      = 0
	ProtectedBranch    = 10
	ArchivedBranch     = 20
	ConfidentialBranch = 30
)
View Source
const (
	BearerPrefix = "Bearer "
)

Variables

View Source
var (
	ErrStop         = errors.New("stop")
	ErrAccessDenied = errors.New("access denied")
)

Functions

func EqualFold

func EqualFold(s, t string) bool

EqualFold is strings.EqualFold, ASCII only. It reports whether s and t are equal, ASCII-case-insensitively.

func GenerateJWT

func GenerateJWT(u *database.User, rid int64, op protocol.Operation, expiresAt time.Time) (string, error)

func JsonEncode

func JsonEncode(w http.ResponseWriter, a any)

func Z1Matcher

func Z1Matcher(r *http.Request, m *mux.RouteMatch) bool

func ZetaEncodeVND

func ZetaEncodeVND(w http.ResponseWriter, a any)

Types

type BearerMD

type BearerMD struct {
	UID                  int64              `json:"uid,string"`
	RID                  int64              `json:"rid,string"`
	Operation            protocol.Operation `json:"operation"`
	jwt.RegisteredClaims                    // v5 new
}

func (*BearerMD) Match

func (t *BearerMD) Match(op protocol.Operation) bool

type HandlerFunc

type HandlerFunc func(http.ResponseWriter, *Request)

type NewKey

type NewKey struct {
	UserName string `json:"username,omitempty"`
	UID      int64  `json:"uid,omitempty"`
	Title    string `json:"title"`
	Content  string `json:"content"`
}

type NewRepo

type NewRepo struct {
	Name          string `json:"name,omitempty"`
	Path          string `json:"path"`
	Description   string `json:"description"`
	VisibleLevel  int    `json:"visible_level,omitempty"`
	DefaultBranch string `json:"default_branch,omitempty"` // current branch
	UserName      string `json:"username,omitempty"`
	UID           int64  `json:"uid,omitempty"`
	NamespacePath string `json:"namespace_path,omitempty"`
	NamespaceID   int64  `json:"namespace_id,omitempty"`
	Empty         bool   `json:"empty,omitempty"`
}

type NewUser

type NewUser struct {
	UserName      string `json:"username"`
	Name          string `json:"name,omitempty"`
	Administrator bool   `json:"administrator"`
	Email         string `json:"email"`
	Password      string `json:"password"`
}

type Request

type Request struct {
	*http.Request
	U *database.User
	N *database.Namespace
	R *database.Repository
}

func (*Request) W

func (r *Request) W(message string) string

type ResponseWriter

type ResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

ResponseWriter shadow ResponseWriter

func NewResponseWriter

func NewResponseWriter(w http.ResponseWriter, r *http.Request) *ResponseWriter

NewResponseWriter bind ResponseWriter

func (*ResponseWriter) F1RemoteAddr

func (w *ResponseWriter) F1RemoteAddr() string

func (*ResponseWriter) StatusCode

func (w *ResponseWriter) StatusCode() int

StatusCode return statusCode

func (*ResponseWriter) Write

func (w *ResponseWriter) Write(data []byte) (int, error)

Write data

func (*ResponseWriter) WriteHeader

func (w *ResponseWriter) WriteHeader(statusCode int)

WriteHeader write header statucode

func (*ResponseWriter) Written

func (w *ResponseWriter) Written() int64

Written return body size

type Server

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

func NewServer

func NewServer(sc *ServerConfig) (*Server, error)

func (*Server) BatchCheck

func (s *Server) BatchCheck(w http.ResponseWriter, r *Request)

POST /{namespace}/{repo}/reference/{refname:.*}/objects/batch

func (*Server) BatchMetadata

func (s *Server) BatchMetadata(w http.ResponseWriter, r *Request)

func (*Server) BatchObjects

func (s *Server) BatchObjects(w http.ResponseWriter, r *Request)

POST /{namespace}/{repo}/objects/batch

func (*Server) BranchPush

func (s *Server) BranchPush(w http.ResponseWriter, r *Request, branchName string)

func (*Server) FetchMetadata

func (s *Server) FetchMetadata(w http.ResponseWriter, r *Request)

func (*Server) GetObject

func (s *Server) GetObject(w http.ResponseWriter, r *Request)

GET /{namespace}/{repo}/objects/{oid}

func (*Server) GetSparseMetadata

func (s *Server) GetSparseMetadata(w http.ResponseWriter, r *Request)

GetSparseMetadata: get commit metadata sparse-tree

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

func (*Server) LsBranchReference

func (s *Server) LsBranchReference(w http.ResponseWriter, r *Request, branchName string)

func (*Server) LsReference

func (s *Server) LsReference(w http.ResponseWriter, r *Request)

GET /{namespace}/{repo}/reference/{refname:.*}

func (*Server) LsTagReference

func (s *Server) LsTagReference(w http.ResponseWriter, r *Request, tagName string)

func (*Server) MakeAuthenticateHeader

func (s *Server) MakeAuthenticateHeader(r *http.Request) string

func (*Server) ManagementRouter

func (s *Server) ManagementRouter(r *mux.Router)

func (*Server) NewKey

func (s *Server) NewKey(w http.ResponseWriter, r *http.Request)

func (*Server) NewRepo

func (s *Server) NewRepo(w http.ResponseWriter, r *http.Request)

func (*Server) NewUser

func (s *Server) NewUser(w http.ResponseWriter, r *http.Request)

func (*Server) OnFunc

func (s *Server) OnFunc(fn HandlerFunc, operation protocol.Operation) http.HandlerFunc

func (*Server) ParseJWT

func (s *Server) ParseJWT(w http.ResponseWriter, r *http.Request, bearerToken string) (*database.User, *BearerMD, error)

func (*Server) ProtocolZ1Router

func (s *Server) ProtocolZ1Router(r *mux.Router)

func (*Server) Push

func (s *Server) Push(w http.ResponseWriter, r *Request)

POST /{namespace}/{repo}/reference/{refname:.*}

func (*Server) PutObject

func (s *Server) PutObject(w http.ResponseWriter, r *Request)

PUT /{namespace}/{repo}/reference/{refname:.*}/objects/{oid}

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) ShareAuthorization

func (s *Server) ShareAuthorization(w http.ResponseWriter, r *http.Request)

ShareAuthorization: POST /{namespace}/{repo}/authorization

func (*Server) ShareObjects

func (s *Server) ShareObjects(w http.ResponseWriter, r *Request)

POST /{namespace}/{repo}/objects/share

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

func (*Server) TagPush

func (s *Server) TagPush(w http.ResponseWriter, r *Request, tagName string)

type ServerConfig

type ServerConfig struct {
	Listen        string          `toml:"listen"`
	Repositories  string          `toml:"repositories"`
	IdleTimeout   serve.Duration  `toml:"idle_timeout,omitempty"`
	ReadTimeout   serve.Duration  `toml:"read_timeout,omitempty"`
	WriteTimeout  serve.Duration  `toml:"write_timeout,omitempty"`
	BannerVersion string          `toml:"banner_version,omitempty"`
	DecryptedKey  string          `toml:"decrypted_key,omitempty"`
	Cache         *serve.Cache    `toml:"cache,omitempty"`
	DB            *serve.Database `toml:"database,omitempty"`
	ZetaOSS       *serve.OSS      `toml:"oss,omitempty"`
}

func NewServerConfig

func NewServerConfig(file string, expandEnv bool) (*ServerConfig, error)

Jump to

Keyboard shortcuts

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