common.go

 1package lfs
 2
 3import "time"
 4
 5const (
 6	// MediaType contains the media type for LFS server requests.
 7	MediaType = "application/vnd.git-lfs+json"
 8
 9	// OperationDownload is the operation name for a download request.
10	OperationDownload = "download"
11
12	// OperationUpload is the operation name for an upload request.
13	OperationUpload = "upload"
14
15	// ActionDownload is the action name for a download request.
16	ActionDownload = OperationDownload
17
18	// ActionUpload is the action name for an upload request.
19	ActionUpload = OperationUpload
20
21	// ActionVerify is the action name for a verify request.
22	ActionVerify = "verify"
23)
24
25// Pointer contains LFS pointer data
26type Pointer struct {
27	Oid  string `json:"oid"`
28	Size int64  `json:"size"`
29}
30
31// PointerBlob associates a Git blob with a Pointer.
32type PointerBlob struct {
33	Hash string
34	Pointer
35}
36
37// ErrorResponse describes the error to the client.
38type ErrorResponse struct {
39	Message          string `json:"message,omitempty"`
40	DocumentationURL string `json:"documentation_url,omitempty"`
41	RequestID        string `json:"request_id,omitempty"`
42}
43
44// BatchResponse contains multiple object metadata Representation structures
45// for use with the batch API.
46// https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#successful-responses
47type BatchResponse struct {
48	Transfer string            `json:"transfer,omitempty"`
49	Objects  []*ObjectResponse `json:"objects"`
50	HashAlgo string            `json:"hash_algo,omitempty"`
51}
52
53// ObjectResponse is object metadata as seen by clients of the LFS server.
54type ObjectResponse struct {
55	Pointer
56	Actions map[string]*Link `json:"actions,omitempty"`
57	Error   *ObjectError     `json:"error,omitempty"`
58}
59
60// Link provides a structure with information about how to access a object.
61type Link struct {
62	Href      string            `json:"href"`
63	Header    map[string]string `json:"header,omitempty"`
64	ExpiresAt *time.Time        `json:"expires_at,omitempty"`
65	ExpiresIn *time.Duration    `json:"expires_in,omitempty"`
66}
67
68// ObjectError defines the JSON structure returned to the client in case of an error.
69type ObjectError struct {
70	Code    int    `json:"code"`
71	Message string `json:"message"`
72}
73
74// BatchRequest contains multiple requests processed in one batch operation.
75// https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#requests
76type BatchRequest struct {
77	Operation string     `json:"operation"`
78	Transfers []string   `json:"transfers,omitempty"`
79	Ref       *Reference `json:"ref,omitempty"`
80	Objects   []Pointer  `json:"objects"`
81	HashAlgo  string     `json:"hash_algo,omitempty"`
82}
83
84// Reference contains a git reference.
85// https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md#ref-property
86type Reference struct {
87	Name string `json:"name"`
88}