Documentation ¶
Index ¶
- Constants
- Variables
- func ListenAndServe(a API, gc *GatewayConfig, listeningMultiAddr string, options ...ServeOption) (*http.Server, error)
- func Serve(a API, gc *GatewayConfig, lis net.Listener, options ...ServeOption) *http.Server
- func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, ...) (int, bool, error)
- type API
- type GatewayConfig
- type GatewaySpec
- type HostnameKey
- type Path
- type Resolved
- type ServeOption
- func CheckVersionOption(daemonVersion string) ServeOption
- func GatewayOption(paths ...string) ServeOption
- func HostnameOption() ServeOption
- func LogOption() ServeOption
- func MetricsCollectionOption(handlerName string) ServeOption
- func MetricsOpenCensusCollectionOption() ServeOption
- func MetricsScrapingOption(path string) ServeOption
- func RedirectOption(path string, redirect string) ServeOption
- func VersionOption(UserAgentVersion, CurrentCommit string) ServeOption
Constants ¶
const APIPath = "/api/v0"
APIPath is the path at which the API is mounted.
const WebUIPath = "/ipfs/bafybeiednzu62vskme5wpoj4bjjikeg3xovfpp4t7vxk5ty2jxdi4mv4bu" // v2.15.0
TODO: move to IPNS
Variables ¶
var WebUIOption = RedirectOption("webui", WebUIPath)
var WebUIPaths = []string{ WebUIPath, "/ipfs/bafybeihcyruaeza7uyjd6ugicbcrqumejf6uf353e5etdkhotqffwtguva", "/ipfs/bafybeiflkjt66aetfgcrgvv75izymd5kc47g6luepqmfq6zsf5w6ueth6y", "/ipfs/bafybeid26vjplsejg7t3nrh7mxmiaaxriebbm4xxrxxdunlk7o337m5sqq", "/ipfs/bafybeif4zkmu7qdhkpf3pnhwxipylqleof7rl6ojbe7mq3fzogz6m4xk3i", "/ipfs/bafybeianwe4vy7sprht5sm3hshvxjeqhwcmvbzq73u55sdhqngmohkjgs4", "/ipfs/bafybeicitin4p7ggmyjaubqpi3xwnagrwarsy6hiihraafk5rcrxqxju6m", "/ipfs/bafybeihpetclqvwb4qnmumvcn7nh4pxrtugrlpw4jgjpqicdxsv7opdm6e", "/ipfs/bafybeibnnxd4etu4tq5fuhu3z5p4rfu3buabfkeyr3o3s4h6wtesvvw6mu", "/ipfs/bafybeid6luolenf4fcsuaw5rgdwpqbyerce4x3mi3hxfdtp5pwco7h7qyq", "/ipfs/bafybeigkbbjnltbd4ewfj7elajsbnjwinyk6tiilczkqsibf3o7dcr6nn4", "/ipfs/bafybeicp23nbcxtt2k2twyfivcbrc6kr3l5lnaiv3ozvwbemtrb7v52r6i", "/ipfs/bafybeidatpz2hli6fgu3zul5woi27ujesdf5o5a7bu622qj6ugharciwjq", "/ipfs/QmfQkD8pBSBCBxWEwFSu4XaDVSWK6bjnNuaWZjMyQbyDub", "/ipfs/QmXc9raDM1M5G5fpBnVyQ71vR4gbnskwnB9iMEzBuLgvoZ", "/ipfs/QmenEBWcAk3tN94fSKpKFtUMwty1qNwSYw3DMDFV6cPBXA", "/ipfs/QmUnXcWZC5Ve21gUseouJsH5mLAyz5JPp8aHsg8qVUUK8e", "/ipfs/QmSDgpiHco5yXdyVTfhKxr3aiJ82ynz8V14QcGKicM3rVh", "/ipfs/QmRuvWJz1Fc8B9cTsAYANHTXqGmKR9DVfY5nvMD1uA2WQ8", "/ipfs/QmQLXHs7K98JNQdWrBB2cQLJahPhmupbDjRuH1b9ibmwVa", "/ipfs/QmXX7YRpU7nNBKfw75VG7Y1c3GwpSAGHRev67XVPgZFv9R", "/ipfs/QmXdu7HWdV6CUaUabd9q2ZeA4iHZLVyDRj3Gi4dsJsWjbr", "/ipfs/QmaaqrHyAQm7gALkRW8DcfGX3u8q9rWKnxEMmf7m9z515w", "/ipfs/QmSHDxWsMPuJQKWmVA1rB5a3NX2Eme5fPqNb63qwaqiqSp", "/ipfs/QmctngrQAt9fjpQUZr7Bx3BsXUcif52eZGTizWhvcShsjz", "/ipfs/QmS2HL9v5YeKgQkkWMvs1EMnFtUowTEdFfSSeMT4pos1e6", "/ipfs/QmR9MzChjp1MdFWik7NjEjqKQMzVmBkdK3dz14A6B5Cupm", "/ipfs/QmRyWyKWmphamkMRnJVjUTzSFSAAZowYP4rnbgnfMXC9Mr", "/ipfs/QmU3o9bvfenhTKhxUakbYrLDnZU7HezAVxPM6Ehjw9Xjqy", "/ipfs/QmPhnvn747LqwPYMJmQVorMaGbMSgA7mRRoyyZYz3DoZRQ", "/ipfs/QmQNHd1suZTktPRhP7DD4nKWG46ZRSxkwHocycHVrK3dYW", "/ipfs/QmNyMYhwJUS1cVvaWoVBhrW8KPj1qmie7rZcWo8f1Bvkhz", "/ipfs/QmVTiRTQ72qiH4usAGT4c6qVxCMv4hFMUH9fvU6mktaXdP", "/ipfs/QmYcP4sp1nraBiCYi6i9kqdaKobrK32yyMpTrM5JDA8a2C", "/ipfs/QmUtMmxgHnDvQq4bpH6Y9MaLN1hpfjJz5LZcq941BEqEXs", "/ipfs/QmPURAjo3oneGH53ovt68UZEBvsc8nNmEhQZEpsVEQUMZE", "/ipfs/QmeSXt32frzhvewLKwA1dePTSjkTfGVwTh55ZcsJxrCSnk", "/ipfs/QmcjeTciMNgEBe4xXvEaA4TQtwTRkXucx7DmKWViXSmX7m", "/ipfs/QmfNbSskgvTXYhuqP8tb9AKbCkyRcCy3WeiXwD9y5LeoqK", "/ipfs/QmPkojhjJkJ5LEGBDrAvdftrjAYmi9GU5Cq27mWvZTDieW", "/ipfs/Qmexhq2sBHnXQbvyP2GfUdbnY7HCagH2Mw5vUNSBn2nxip", }
this is a list of all past webUI paths.
Functions ¶
func ListenAndServe ¶
func ListenAndServe(a API, gc *GatewayConfig, listeningMultiAddr string, options ...ServeOption) (*http.Server, error)
ListenAndServe runs an HTTP server listening at |listeningMultiAddr| with the given serve options. The address must be provided in multiaddr format.
TODO intelligently parse address strings in other formats so long as they unambiguously map to a valid multiaddr. e.g. for convenience, ":8080" should map to "/ip4/0.0.0.0/tcp/8080".
func Serve ¶
func Serve(a API, gc *GatewayConfig, lis net.Listener, options ...ServeOption) *http.Server
Serve accepts incoming HTTP connections on the listener and pass them to ServeOption handlers.
func ServeContent ¶
func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, content io.ReadSeeker) (int, bool, error)
ServeContent replies to the request using the content in the provided ReadSeeker and returns the status code written and any error encountered during a write. It wraps http.ServeContent which takes care of If-None-Match+Etag, Content-Length and range requests.
Types ¶
type API ¶
type API interface { // NewSession requests a link system that can be used for the duration of a given request context. // The link system returned should be consistent for the life of the context - CIDs which have at // some point been accessible to the link system at some point during the session are expected to // continue to be available for the duration of the session. NewSession(context.Context) *ipld.LinkSystem // FetcherForSession describes dags that that the session is requesting to load. These dags should // be fetchd into the local linksystem if not already present. FetcherForSession(*ipld.LinkSystem) fetcher.Fetcher // Resolver requests resolutions of dns names, and acts as an interface over go-namesys. // If resolution is not supported, the name argument should be returned directly. Resolve(ctx context.Context, name string) (string, error) }
API defines the backing interface needed for this gateway frontend to operate.
type GatewayConfig ¶
type GatewayConfig struct { // HTTPHeaders configures the headers that should be returned by this // gateway. HTTPHeaders map[string][]string // HTTP headers to return with the gateway // RootRedirect is the path to which requests to `/` on this gateway // should be redirected. RootRedirect string // PathPrefixes is an array of acceptable url paths that a client can // specify in X-Ipfs-Path-Prefix header. // // The X-Ipfs-Path-Prefix header is used to specify a base path to prepend // to links in directory listings and for trailing-slash redirects. It is // intended to be set by a frontend http proxy like nginx. // // Example: To mount blog.ipfs.io (a DNSLink site) at ipfs.io/blog // set PathPrefixes to ["/blog"] and nginx config to translate paths // and pass Host header (for DNSLink): // location /blog/ { // rewrite "^/blog(/.*)$" $1 break; // proxy_set_header Host blog.ipfs.io; // proxy_set_header X-Ipfs-Gateway-Prefix /blog; // proxy_pass http://127.0.0.1:8080; // } PathPrefixes []string // FIXME: Not yet implemented APICommands []string // NoFetch configures the gateway to _not_ fetch blocks in response to // requests. NoFetch bool // NoDNSLink configures the gateway to _not_ perform DNS TXT record // lookups in response to requests with values in `Host` HTTP header. // This flag can be overridden per FQDN in PublicGateways. NoDNSLink bool // PublicGateways configures behavior of known public gateways. // Each key is a fully qualified domain name (FQDN). PublicGateways map[string]*GatewaySpec }
GatewayConfig describes the overall configuration for the gateway
type GatewaySpec ¶
type GatewaySpec struct { // Paths is explicit list of path prefixes that should be handled by // this gateway. Example: `["/ipfs", "/ipns", "/api"]` Paths []string // UseSubdomains indicates whether or not this gateway uses subdomains // for IPFS resources instead of paths. That is: http://CID.ipfs.GATEWAY/... // // If this flag is set, any /ipns/$id and/or /ipfs/$id paths in PathPrefixes // will be permanently redirected to http://$id.[ipns|ipfs].$gateway/. // // We do not support using both paths and subdomains for a single domain // for security reasons (Origin isolation). UseSubdomains bool // NoDNSLink configures this gateway to _not_ resolve DNSLink for the FQDN // provided in `Host` HTTP header. NoDNSLink bool }
GatewaySpec is the specification for an individual public gateway.
type Path ¶
type Path interface { // String returns the path as a string. String() string // Namespace returns the first component of the path. // // For example path "/ipfs/QmHash", calling Namespace() will return "ipfs" // // Calling this method on invalid paths (IsValid() != nil) will result in // empty string Namespace() string // Mutable returns false if the data pointed to by this path in guaranteed // to not change. // // Note that resolved mutable path can be immutable. Mutable() bool // IsValid checks if this path is a valid ipfs Path, returning nil iff it is // valid IsValid() error }
Path is a generic wrapper for paths used in the API. A path can be resolved to a CID using one of Resolve functions in the API.
Paths must be prefixed with a valid prefix:
* /ipfs - Immutable unixfs path (files) * /ipld - Immutable ipld path (data) * /ipns - Mutable names. Usually resolves to one of the immutable paths TODO: /local (MFS)
type Resolved ¶
type Resolved interface { // Cid returns the CID of the node referenced by the path. Remainder of the // path is guaranteed to be within the node. // // Examples: // If you have 3 linked objects: QmRoot -> A -> B: // // cidB := {"foo": {"bar": 42 }} // cidA := {"B": {"/": cidB }} // cidRoot := {"A": {"/": cidA }} // // And resolve paths: // // * "/ipfs/${cidRoot}" // * Calling Cid() will return `cidRoot` // * Calling Root() will return `cidRoot` // * Calling Remainder() will return “ // // * "/ipfs/${cidRoot}/A" // * Calling Cid() will return `cidA` // * Calling Root() will return `cidRoot` // * Calling Remainder() will return “ // // * "/ipfs/${cidRoot}/A/B/foo" // * Calling Cid() will return `cidB` // * Calling Root() will return `cidRoot` // * Calling Remainder() will return `foo` // // * "/ipfs/${cidRoot}/A/B/foo/bar" // * Calling Cid() will return `cidB` // * Calling Root() will return `cidRoot` // * Calling Remainder() will return `foo/bar` Cid() cid.Cid // Root returns the CID of the root object of the path // // Example: // If you have 3 linked objects: QmRoot -> A -> B, and resolve path // "/ipfs/QmRoot/A/B", the Root method will return the CID of object QmRoot // // For more examples see the documentation of Cid() method Root() cid.Cid // Remainder returns unresolved part of the path // // Example: // If you have 2 linked objects: QmRoot -> A, where A is a CBOR node // containing the following data: // // {"foo": {"bar": 42 }} // // When resolving "/ipld/QmRoot/A/foo/bar", Remainder will return "foo/bar" // // For more examples see the documentation of Cid() method Remainder() string Path }
Resolved is a path which was resolved to the last resolvable node. ResolvedPaths are guaranteed to return nil from `IsValid`
func IpfsPath ¶
func IpfsPath(c cid.Cid) Resolved
IpfsPath creates new /ipfs path from the provided CID
func IpldPath ¶
func IpldPath(c cid.Cid) Resolved
IpldPath creates new /ipld path from the provided CID
func NewResolvedPath ¶
NewResolvedPath creates new Resolved path. This function performs no checks and is intended to be used by resolver implementations. Incorrect inputs may cause panics. Handle with care.
type ServeOption ¶
ServeOption registers any HTTP handlers it provides on the given mux. It returns the mux to expose to future options, which may be a new mux if it is interested in mediating requests to future options, or the same mux initially passed in if not.
func CheckVersionOption ¶
func CheckVersionOption(daemonVersion string) ServeOption
CheckVersionOption returns a ServeOption that checks whether the client ipfs version matches. Does nothing when the user agent string does not contain `/go-ipfs/`
func GatewayOption ¶
func GatewayOption(paths ...string) ServeOption
func HostnameOption ¶
func HostnameOption() ServeOption
HostnameOption rewrites an incoming request based on the Host header.
func LogOption ¶
func LogOption() ServeOption
func MetricsCollectionOption ¶
func MetricsCollectionOption(handlerName string) ServeOption
MetricsCollectionOption adds collection of net/http-related metrics.
func MetricsOpenCensusCollectionOption ¶
func MetricsOpenCensusCollectionOption() ServeOption
This adds collection of OpenCensus metrics
func MetricsScrapingOption ¶
func MetricsScrapingOption(path string) ServeOption
MetricsScrapingOption adds the scraping endpoint which Prometheus uses to fetch metrics.
func RedirectOption ¶
func RedirectOption(path string, redirect string) ServeOption
func VersionOption ¶
func VersionOption(UserAgentVersion, CurrentCommit string) ServeOption