{"modulePath":"github.com/ohlinux/git-lfs","version":"v1.5.4","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package api\n\nPackage api provides the interface for querying LFS servers (metadata) NOTE: Subject to change, do not rely on this package from outside git-lfs source\n\nNOTE: Subject to change, do not rely on this package from outside git-lfs source\n\nNOTE: Subject to change, do not rely on this package from outside git-lfs source\n\nNOTE: Subject to change, do not rely on this package from outside git-lfs source\n\nNOTE: Subject to change, do not rely on this package from outside git-lfs source\n\nNOTE: Subject to change, do not rely on this package from outside git-lfs source\n\nNOTE: Subject to change, do not rely on this package from outside git-lfs source\n\n## Constants\n\n```go\nconst (\n\tMediaType = \"application/vnd.git-lfs+json; charset=utf-8\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// ErrNoOperationGiven is an error which is returned when no operation\n\t// is provided in a RequestSchema object.\n\tErrNoOperationGiven = errors.New(\"lfs/api: no operation provided in schema\")\n)\n```\n\n## Functions\n\n```go\nfunc DoBatchRequest(cfg *config.Configuration, req *http.Request) (*http.Response, *batchResponse, error)\n```\ndoApiBatchRequest runs the request to the LFS batch API. If the API returns a 401, the repo will be marked as having private access and the request will be re-run. When the repo is marked as having private access, credentials will be retrieved.\n\n```go\nfunc DoRequest(req *http.Request, useCreds bool) (*http.Response, error)\n```\nDoRequest runs a request to the LFS API, without parsing the response body. If the API returns a 401, the repo will be marked as having private access and the request will be re-run. When the repo is marked as having private access, credentials will be retrieved.\n\n```go\nfunc NewBatchRequest(cfg *config.Configuration, operation string) (*http.Request, error)\n```\n\n```go\nfunc NewRequest(cfg *config.Configuration, method, oid string) (*http.Request, error)\n```\n\n```go\nfunc ObjectUrl(endpoint config.Endpoint, oid string) (*url.URL, error)\n```\n\n```go\nfunc VerifyUpload(cfg *config.Configuration, obj *ObjectResource) error\n```\nVerifyUpload calls the \"verify\" API link relation on obj if it exists\n\n## Types\n\n```go\ntype Client struct {\n\t// Locks is the LockService used to interact with the Git LFS file-\n\t// locking API.\n\tLocks LockService\n\t// contains filtered or unexported fields\n}\n```\nClient exposes the LFS API to callers through a multitude of different services and transport mechanisms. Callers can make a \\*RequestSchema using any service that is attached to the Client, and then execute a request based on that schema using the \\`Do()\\` method.\n\nA prototypical example follows: \\`\\`\\`\n\n\tapiResponse, schema := client.Locks.Lock(request)\n\tresp, err := client.Do(schema)\n\tif err != nil {\n\t    handleErr(err)\n\t}\n\n\tfmt.Println(apiResponse.Lock)\n\n\\`\\`\\`\n\n```go\nfunc NewClient(lifecycle Lifecycle) *Client\n```\nNewClient instantiates and returns a new instance of \\*Client, with the given lifecycle.\n\nIf no lifecycle is given, a HttpLifecycle is used by default.\n\n```go\nfunc (c *Client) Do(schema *RequestSchema) (Response, error)\n```\nDo preforms the request assosicated with the given \\*RequestSchema by delegating into the Lifecycle in use.\n\nIf any error was encountered while either building, executing or cleaning up the request, then it will be returned immediately, and the request can be treated as invalid.\n\nIf no error occured, an api.Response will be returned, along with a \\`nil\\` error. At this point, the body of the response has been serialized into \\`schema.Into\\`, and the body has been closed.\n\n```go\ntype Committer struct {\n\t// Name is the name of the individual who would like to obtain the\n\t// lock, for instance: \"Rick Olson\".\n\tName string `json:\"name\"`\n\t// Email is the email assopsicated with the individual who would\n\t// like to obtain the lock, for instance: \"rick@github.com\".\n\tEmail string `json:\"email\"`\n}\n```\nCommitter represents a \"First Last \\\u003cemail@domain.com\u003e\" pair.\n\n```go\nfunc CurrentCommitter() Committer\n```\nCurrentCommitter returns a Committer instance populated with the same credentials as would be used to author a commit. In particular, the \"user.name\" and \"user.email\" configuration values are used from the config.Config singleton.\n\n```go\ntype EndpointSource interface {\n\t// Endpoint returns the `config.Endpoint` assosciated with a given\n\t// operation.\n\tEndpoint(operation string) config.Endpoint\n}\n```\nEndpointSource is an interface which encapsulates the behavior of returning \\`config.Endpoint\\`s based on a particular operation.\n\n```go\ntype Filter struct {\n\t// Property is the property to search against.\n\t// Value is the value that the property must take.\n\tProperty, Value string\n}\n```\nFilter represents a single qualifier to apply against a set of locks.\n\n```go\ntype HttpLifecycle struct {\n\t// contains filtered or unexported fields\n}\n```\nHttpLifecycle serves as the default implementation of the Lifecycle interface for HTTP requests. Internally, it leverages the \\*http.Client type to execute HTTP requests against a root \\*url.URL, as given in \\`NewHttpLifecycle\\`.\n\n```go\nfunc NewHttpLifecycle(endpoints EndpointSource) *HttpLifecycle\n```\nNewHttpLifecycle initializes a new instance of the \\*HttpLifecycle type with a new \\*http.Client, and the given root (see above).\n\n```go\nfunc (l *HttpLifecycle) Build(schema *RequestSchema) (*http.Request, error)\n```\nBuild implements the Lifecycle.Build function.\n\nHttpLifecycle in particular, builds an absolute path by parsing and then relativizing the \\`schema.Path\\` with respsect to the \\`HttpLifecycle.root\\`. If there was an error in determining this URL, then that error will be returned,\n\nAfter this is complete, a body is attached to the request if the schema contained one. If a body was present, and there an error occurred while serializing it into JSON, then that error will be returned and the \\*http.Request will not be generated.\n\nIn all cases, credentials are attached to the HTTP request as described in the \\`auth\\` package (see github.com/git-lfs/git-lfs/auth#GetCreds).\n\nFinally, all of these components are combined together and the resulting request is returned.\n\n```go\nfunc (l *HttpLifecycle) Cleanup(resp Response) error\n```\nCleanup implements the Lifecycle.Cleanup function by closing the Body attached to the response.\n\n```go\nfunc (l *HttpLifecycle) Execute(req *http.Request, into interface{}) (Response, error)\n```\nExecute implements the Lifecycle.Execute function.\n\nInternally, the \\*http.Client is used to execute the underlying \\*http.Request. If the client returned an error corresponding to a failure to make the request, then that error will be returned immediately, and the response is guaranteed not to be serialized.\n\nOnce the response has been gathered from the server, it is unmarshled into the given \\`into interface{}\\` which is identical to the one provided in the original RequestSchema. If an error occured while decoding, then that error is returned.\n\nOtherwise, the api.Response is returned, along with no error, signaling that the request completed successfully.\n\n```go\ntype HttpResponse struct {\n\t// contains filtered or unexported fields\n}\n```\nHttpResponse is an implementation of the Response interface capable of handling HTTP responses. At its core, it works by wrapping an \\*http.Response.\n\n```go\nfunc WrapHttpResponse(r *http.Response) *HttpResponse\n```\nWrapHttpResponse returns a wrapped \\*HttpResponse implementing the Repsonse type by using the given \\*http.Response.\n\n```go\nfunc (h *HttpResponse) Body() io.ReadCloser\n```\nBody implements the Response.Body function, and returns the body as given by the underlying \\*http.Response.\n\n```go\nfunc (h *HttpResponse) Header() http.Header\n```\nHeader returns the underlying \\*http.Response's header.\n\n```go\nfunc (h *HttpResponse) Proto() string\n```\nProto implements the Response.Proto function, and returns the proto given by the underlying \\*http.Response.\n\n```go\nfunc (h *HttpResponse) Status() string\n```\nStatus implements the Response.Status function, and returns the status given by the underlying \\*http.Response.\n\n```go\nfunc (h *HttpResponse) StatusCode() int\n```\nStatusCode implements the Response.StatusCode function, and returns the status code given by the underlying \\*http.Response.\n\n```go\ntype Lifecycle interface {\n\t// Build creates a sendable request by using the given RequestSchema as\n\t// a model.\n\tBuild(req *RequestSchema) (*http.Request, error)\n\n\t// Execute transforms generated request into a wrapped repsonse, (and\n\t// optionally an error, if the request failed), and serializes the\n\t// response into the `into interface{}`, if one was provided.\n\tExecute(req *http.Request, into interface{}) (Response, error)\n\n\t// Cleanup is called after the request has been completed and its\n\t// response has been processed. It is meant to preform any post-request\n\t// actions necessary, like closing or resetting the connection. If an\n\t// error was encountered in doing this operation, it should be returned\n\t// from this method, otherwise nil.\n\tCleanup(resp Response) error\n}\n```\nA Lifecycle represents and encapsulates the behavior on an API request from inception to cleanup.\n\nAt a high level, it turns an \\*api.RequestSchema into an api.Response (and optionally an error). Lifecycle does so by providing several more fine-grained methods that are used by the client to manage the lifecycle of a request in a platform-agnostic fashion.\n\n```go\ntype LinkRelation struct {\n\tHref      string            `json:\"href\"`\n\tHeader    map[string]string `json:\"header,omitempty\"`\n\tExpiresAt time.Time         `json:\"expires_at,omitempty\"`\n}\n```\n\n```go\ntype Lock struct {\n\t// Id is the unique identifier corresponding to this particular Lock. It\n\t// must be consistent with the local copy, and the server's copy.\n\tId string `json:\"id\"`\n\t// Path is an absolute path to the file that is locked as a part of this\n\t// lock.\n\tPath string `json:\"path\"`\n\t// Committer is the author who initiated this lock.\n\tCommitter Committer `json:\"committer\"`\n\t// CommitSHA is the commit that this Lock was created against. It is\n\t// strictly equal to the SHA of the minimum commit negotiated in order\n\t// to create this lock.\n\tCommitSHA string `json:\"commit_sha\"`\n\t// LockedAt is a required parameter that represents the instant in time\n\t// that this lock was created. For most server implementations, this\n\t// should be set to the instant at which the lock was initially\n\t// received.\n\tLockedAt time.Time `json:\"locked_at\"`\n\t// ExpiresAt is an optional parameter that represents the instant in\n\t// time that the lock stopped being active. If the lock is still active,\n\t// the server can either a) not send this field, or b) send the\n\t// zero-value of time.Time.\n\tUnlockedAt time.Time `json:\"unlocked_at,omitempty\"`\n}\n```\nLock represents a single lock that against a particular path.\n\nLocks returned from the API may or may not be currently active, according to the Expired flag.\n\n```go\nfunc (l *Lock) Active() bool\n```\nActive returns whether or not the given lock is still active against the file that it is protecting.\n\n```go\ntype LockList struct {\n\t// Locks is the set of locks returned back, typically matching the query\n\t// parameters sent in the LockListRequest call. If no locks were matched\n\t// from a given query, then `Locks` will be represented as an empty\n\t// array.\n\tLocks []Lock `json:\"locks\"`\n\t// NextCursor returns the Id of the Lock the client should update its\n\t// cursor to, if there are multiple pages of results for a particular\n\t// `LockListRequest`.\n\tNextCursor string `json:\"next_cursor,omitempty\"`\n\t// Err populates any error that was encountered during the search. If no\n\t// error was encountered and the operation was succesful, then a value\n\t// of nil will be passed here.\n\tErr string `json:\"error,omitempty\"`\n}\n```\nLockList encapsulates a set of Locks.\n\n```go\ntype LockRequest struct {\n\t// Path is the path that the client would like to obtain a lock against.\n\tPath string `json:\"path\"`\n\t// LatestRemoteCommit is the SHA of the last known commit from the\n\t// remote that we are trying to create the lock against, as found in\n\t// `.git/refs/origin/\u003cname\u003e`.\n\tLatestRemoteCommit string `json:\"latest_remote_commit\"`\n\t// Committer is the individual that wishes to obtain the lock.\n\tCommitter Committer `json:\"committer\"`\n}\n```\nLockRequest encapsulates the payload sent across the API when a client would like to obtain a lock against a particular path on a given remote.\n\n```go\ntype LockResponse struct {\n\t// Lock is the Lock that was optionally created in response to the\n\t// payload that was sent (see above). If the lock already exists, then\n\t// the existing lock is sent in this field instead, and the author of\n\t// that lock remains the same, meaning that the client failed to obtain\n\t// that lock. An HTTP status of \"409 - Conflict\" is used here.\n\t//\n\t// If the lock was unable to be created, this field will hold the\n\t// zero-value of Lock and the Err field will provide a more detailed set\n\t// of information.\n\t//\n\t// If an error was experienced in creating this lock, then the\n\t// zero-value of Lock should be sent here instead.\n\tLock *Lock `json:\"lock\"`\n\t// CommitNeeded holds the minimum commit SHA that client must have to\n\t// obtain the lock.\n\tCommitNeeded string `json:\"commit_needed,omitempty\"`\n\t// Err is the optional error that was encountered while trying to create\n\t// the above lock.\n\tErr string `json:\"error,omitempty\"`\n}\n```\nLockResponse encapsulates the information sent over the API in response to a \\`LockRequest\\`.\n\n```go\ntype LockSearchRequest struct {\n\t// Filters is the set of filters to query against. If the client wishes\n\t// to obtain a list of all locks, an empty array should be passed here.\n\tFilters []Filter\n\t// Cursor is an optional field used to tell the server which lock was\n\t// seen last, if scanning through multiple pages of results.\n\t//\n\t// Servers must return a list of locks sorted in reverse chronological\n\t// order, so the Cursor provides a consistent method of viewing all\n\t// locks, even if more were created between two requests.\n\tCursor string\n\t// Limit is the maximum number of locks to return in a single page.\n\tLimit int\n}\n```\nLockSearchRequest encapsulates the request sent to the server when the client would like a list of locks that match the given criteria.\n\n```go\ntype LockService struct{}\n```\nLockService is an API service which encapsulates the Git LFS Locking API.\n\n```go\nfunc (s *LockService) Lock(req *LockRequest) (*RequestSchema, *LockResponse)\n```\nLock generates a \\*RequestSchema that is used to preform the \"attempt lock\" API method.\n\nIf a lock is already present, or if the server was unable to generate the lock, the Err field of the LockResponse type will be populated with a more detailed error describing the situation.\n\nIf the caller does not have the minimum commit necessary to obtain the lock on that file, then the CommitNeeded field will be populated in the LockResponse, signaling that more commits are needed.\n\nIn the successful case, a new Lock will be returned and granted to the caller.\n\n```go\nfunc (s *LockService) Search(req *LockSearchRequest) (*RequestSchema, *LockList)\n```\nSearch generates a \\*RequestSchema that is used to preform the \"search for locks\" API method.\n\nSearches can be scoped to match specific parameters by using the Filters field in the given LockSearchRequest. If no matching Locks were found, then the Locks field of the response will be empty.\n\nIf the client expects that the server will return many locks, then the client can choose to paginate that response. Pagination is preformed by limiting the amount of results per page, and the server will inform the client of the ID of the last returned lock. Since the server is guaranteed to return results in reverse chronological order, the client simply sends the last ID it processed along with the next request, and the server will continue where it left off.\n\nIf the server was unable to process the lock search request, then the Error field will be populated in the response.\n\nIn the successful case, one or more locks will be returned as a part of the response.\n\n```go\nfunc (s *LockService) Unlock(id string, force bool) (*RequestSchema, *UnlockResponse)\n```\nUnlock generates a \\*RequestSchema that is used to preform the \"unlock\" API method, against a particular lock potentially with --force.\n\nThis method's corresponding response type will either contain a reference to the lock that was unlocked, or an error that was experienced by the server in unlocking it.\n\n```go\ntype ObjectError struct {\n\tCode    int    `json:\"code\"`\n\tMessage string `json:\"message\"`\n}\n```\n\n```go\nfunc (e *ObjectError) Error() string\n```\n\n```go\ntype ObjectResource struct {\n\tOid           string                   `json:\"oid,omitempty\"`\n\tSize          int64                    `json:\"size\"`\n\tAuthenticated bool                     `json:\"authenticated,omitempty\"`\n\tActions       map[string]*LinkRelation `json:\"actions,omitempty\"`\n\tLinks         map[string]*LinkRelation `json:\"_links,omitempty\"`\n\tError         *ObjectError             `json:\"error,omitempty\"`\n}\n```\n\n```go\nfunc Batch(cfg *config.Configuration, objects []*ObjectResource, operation string, transferAdapters []string) (objs []*ObjectResource, transferAdapter string, e error)\n```\nBatch calls the batch API and returns object results\n\n```go\nfunc BatchOrLegacy(cfg *config.Configuration, objects []*ObjectResource, operation string, transferAdapters []string) (objs []*ObjectResource, transferAdapter string, e error)\n```\nBatchOrLegacy calls the Batch API and falls back on the Legacy API This is for simplicity, legacy route is not most optimal (serial) TODO LEGACY API: remove when legacy API removed\n\n```go\nfunc BatchOrLegacySingle(cfg *config.Configuration, inobj *ObjectResource, operation string, transferAdapters []string) (obj *ObjectResource, transferAdapter string, e error)\n```\n\n```go\nfunc DoLegacyRequest(cfg *config.Configuration, req *http.Request) (*http.Response, *ObjectResource, error)\n```\ndoLegacyApiRequest runs the request to the LFS legacy API.\n\n```go\nfunc DownloadCheck(cfg *config.Configuration, oid string) (*ObjectResource, error)\n```\nTODO LEGACY API: remove when legacy API removed\n\n```go\nfunc Legacy(cfg *config.Configuration, objects []*ObjectResource, operation string) ([]*ObjectResource, error)\n```\nLegacy calls the legacy API serially and returns ObjectResources TODO LEGACY API: remove when legacy API removed\n\n```go\nfunc UploadCheck(cfg *config.Configuration, oid string, size int64) (*ObjectResource, error)\n```\nTODO LEGACY API: remove when legacy API removed\n\n```go\nfunc (o *ObjectResource) IsExpired(now time.Time) (time.Time, bool)\n```\nIsExpired returns true, and the time of the expired action, if any of the actions in this object resource have an ExpiresAt field that is after the given instant \"now\".\n\nIf the object contains no actions, or none of the actions it does contain have non-zero ExpiresAt fields, the object is not expired.\n\n```go\nfunc (o *ObjectResource) NeedsAuth() bool\n```\n\n```go\nfunc (o *ObjectResource) NewRequest(relation, method string) (*http.Request, error)\n```\nTODO LEGACY API: remove when legacy API removed\n\n```go\nfunc (o *ObjectResource) Rel(name string) (*LinkRelation, bool)\n```\n\n```go\ntype Operation string\n```\n\n```go\nconst (\n\tUploadOperation   Operation = \"upload\"\n\tDownloadOperation Operation = \"download\"\n)\n```\n\n```go\ntype RequestSchema struct {\n\t// Method is the method that should be used when making a particular API\n\t// call.\n\tMethod string\n\t// Path is the relative path that this API call should be made against.\n\tPath string\n\t// Operation is the operation used to determine which endpoint to make\n\t// the request against (see github.com/git-lfs/git-lfs/config).\n\tOperation Operation\n\t// Query is the query parameters used in the request URI.\n\tQuery map[string]string\n\t// Body is the body of the request.\n\tBody interface{}\n\t// Into is an optional field used to represent the data structure into\n\t// which a response should be serialized.\n\tInto interface{}\n}\n```\nRequestSchema provides a schema from which to generate sendable requests.\n\n```go\ntype Response interface {\n\t// Status is a human-readable string representing the status the\n\t// response was returned with.\n\tStatus() string\n\t// StatusCode is the numeric code associated with a particular status.\n\tStatusCode() int\n\t// Proto is the protocol with which the response was delivered.\n\tProto() string\n\t// Body returns an io.ReadCloser containg the contents of the response's\n\t// body.\n\tBody() io.ReadCloser\n}\n```\nResponse is an interface that represents a response returned as a result of executing an API call. It is designed to represent itself across multiple response type, be it HTTP, SSH, or something else.\n\nThe Response interface is meant to be small enough such that it can be sufficiently general, but is easily accessible if a caller needs more information specific to a particular protocol.\n\n```go\ntype UnlockRequest struct {\n\t// Id is the Id of the lock that the user wishes to unlock.\n\tId string `json:\"id\"`\n\t// Force determines whether or not the lock should be \"forcibly\"\n\t// unlocked; that is to say whether or not a given individual should be\n\t// able to break a different individual's lock.\n\tForce bool `json:\"force\"`\n}\n```\nUnlockRequest encapsulates the data sent in an API request to remove a lock.\n\n```go\ntype UnlockResponse struct {\n\t// Lock is the lock corresponding to the asked-about lock in the\n\t// `UnlockPayload` (see above). If no matching lock was found, this\n\t// field will take the zero-value of Lock, and Err will be non-nil.\n\tLock *Lock `json:\"lock\"`\n\t// Err is an optional field which holds any error that was experienced\n\t// while removing the lock.\n\tErr string `json:\"error,omitempty\"`\n}\n```\nUnlockResponse is the result sent back from the API when asked to remove a lock.\n\n","path":"github.com/ohlinux/git-lfs/api","name":"api","synopsis":"Package api provides the interface for querying LFS servers (metadata) NOTE: Subject to change, do not rely on this package from outside git-lfs source NOTE: Subject to change, do not rely on this package from outside git-lfs source NOTE: Subject to change, do not rely on this package from outside git-lfs source NOTE: Subject to change, do not rely on this package from outside git-lfs source NOTE: Subject to change, do not rely on this package from outside git-lfs source NOTE: Subject to change, do not rely on this package from outside git-lfs source NOTE: Subject to change, do not rely on this package from outside git-lfs source","isRedistributable":true}
