A ServerOps provides the external operations (accessing module information and so on) needed by the Server.
| 24 | // A ServerOps provides the external operations |
| 25 | // (accessing module information and so on) needed by the Server. |
| 26 | type ServerOps interface { |
| 27 | // NewContext returns the context to use for the request r. |
| 28 | NewContext(r *http.Request) (context.Context, error) |
| 29 | // List, Latest, Info, GoMod, and Zip all return a File to be sent to a client. |
| 30 | // The File will be closed after its contents are sent. |
| 31 | // In the case of an error, if the error satisfies errors.Is(err, os.ErrNotFound), |
| 32 | // the server responds with an HTTP 404 error; |
| 33 | // otherwise it responds with an HTTP 500 error. |
| 34 | // List returns a list of tagged versions of the module identified by path. |
| 35 | // The versions should all be canonical semantic versions |
| 36 | // and formatted in a text listing, one per line. |
| 37 | // Pseudo-versions derived from untagged commits should be omitted. |
| 38 | // The go command exposes this list in 'go list -m -versions' output |
| 39 | // and also uses it to resolve wildcards like 'go get m@v1.2'. |
| 40 | List(ctx context.Context, path string) (File, error) |
| 41 | // Latest returns an info file for the latest known version of the module identified by path. |
| 42 | // The go command uses this for 'go get m' or 'go get m@latest' |
| 43 | // but only after finding no suitable version among the ones returned by List. |
| 44 | // Typically, Latest should return a pseudo-version for the latest known commit. |
| 45 | Latest(ctx context.Context, path string) (File, error) |
| 46 | // Info opens and returns the module version's info file. |
| 47 | // The requested version can be a canonical semantic version |
| 48 | // but can also be an arbitrary version reference, like "master". |
| 49 | // |
| 50 | // The metadata in the returned file should be a JSON object corresponding |
| 51 | // to the Go type |
| 52 | // |
| 53 | // type Info struct { |
| 54 | // Version string |
| 55 | // Time time.Time |
| 56 | // } |
| 57 | // |
| 58 | // where the version is the resolved canonical semantic version |
| 59 | // and the time is the commit or publication time of that version |
| 60 | // (for use with go list -m). |
| 61 | // The NewInfo function can be used to construct an info File. |
| 62 | // |
| 63 | // Proxies should obtain the module version information by |
| 64 | // executing 'go mod download -json' and caching the file |
| 65 | // listed in the Info field. |
| 66 | Info(ctx context.Context, m module.Version) (File, error) |
| 67 | // GoMod opens and returns the module's go.mod file. |
| 68 | // The requested version is a canonical semantic version. |
| 69 | // |
| 70 | // Proxies should obtain the module version information by |
| 71 | // executing 'go mod download -json' and caching the file |
| 72 | // listed in the GoMod field. |
| 73 | GoMod(ctx context.Context, m module.Version) (File, error) |
| 74 | // Zip opens and returns the module's zip file. |
| 75 | // The requested version is a canonical semantic version. |
| 76 | // |
| 77 | // Proxies should obtain the module version information by |
| 78 | // executing 'go mod download -json' and caching the file |
| 79 | // listed in the Zip field. |
| 80 | Zip(ctx context.Context, m module.Version) (File, error) |
| 81 | } |
| 82 | |
| 83 | // A File is a file to be served, typically an *os.File or the result of calling MemFile or NewInfo. |