Documentation
¶
Index ¶
- Constants
- func DatasetRefFromCtx(ctx context.Context) repo.DatasetRef
- func DatasetRefFromPath(path string) (repo.DatasetRef, error)
- func DatasetRefFromReq(r *http.Request) (repo.DatasetRef, error)
- func HTTPPathToQriPath(path string) string
- func HTTPSRedirect()
- func NewServerRoutes(s *Server) *http.ServeMux
- func StartServer(c *Config, s *http.Server) error
- type Config
- type DataResponse
- type DatasetHandlers
- func (h *DatasetHandlers) AddHandler(w http.ResponseWriter, r *http.Request)
- func (h *DatasetHandlers) DataHandler(w http.ResponseWriter, r *http.Request)
- func (h *DatasetHandlers) DiffHandler(w http.ResponseWriter, r *http.Request)
- func (h *DatasetHandlers) GetHandler(w http.ResponseWriter, r *http.Request)
- func (h *DatasetHandlers) InitHandler(w http.ResponseWriter, r *http.Request)
- func (h *DatasetHandlers) ListHandler(w http.ResponseWriter, r *http.Request)
- func (h *DatasetHandlers) PeerListHandler(w http.ResponseWriter, r *http.Request)
- func (h *DatasetHandlers) RemoveHandler(w http.ResponseWriter, r *http.Request)
- func (h *DatasetHandlers) RenameHandler(w http.ResponseWriter, r *http.Request)
- func (h *DatasetHandlers) SaveHandler(w http.ResponseWriter, r *http.Request)
- func (h *DatasetHandlers) ZipDatasetHandler(w http.ResponseWriter, r *http.Request)
- type HistoryHandlers
- type PeerHandlers
- func (h *PeerHandlers) ConnectToPeerHandler(w http.ResponseWriter, r *http.Request)
- func (h *PeerHandlers) ConnectionsHandler(w http.ResponseWriter, r *http.Request)
- func (h *PeerHandlers) PeerHandler(w http.ResponseWriter, r *http.Request)
- func (h *PeerHandlers) PeersHandler(w http.ResponseWriter, r *http.Request)
- type ProfileHandlers
- type QriCtxKey
- type RenameReqParams
- type RootHandler
- type Server
- func (s *Server) HandleIPFSPath(w http.ResponseWriter, r *http.Request)
- func (s *Server) HandleIPNSPath(w http.ResponseWriter, r *http.Request)
- func (s *Server) Serve() (err error)
- func (s *Server) ServeRPC()
- func (s *Server) ServeWebapp()
- func (s *Server) WebappHandler(w http.ResponseWriter, r *http.Request)
Constants ¶
const ( ModeDevelop = "develop" ModeProduction = "production" ModeTest = "test" DefaultAPIPort = "2503" DefaultRPCPort = "2504" DefaultWebappPort = "2505" )
server modes
Variables ¶
This section is empty.
Functions ¶
func DatasetRefFromCtx ¶ added in v0.1.2
func DatasetRefFromCtx(ctx context.Context) repo.DatasetRef
DatasetRefFromCtx extracts a Dataset reference from a given context if one is set, returning nil otherwise
func DatasetRefFromPath ¶ added in v0.1.2
func DatasetRefFromPath(path string) (repo.DatasetRef, error)
DatasetRefFromPath parses a path and returns a datasetRef
func DatasetRefFromReq ¶ added in v0.1.2
func DatasetRefFromReq(r *http.Request) (repo.DatasetRef, error)
DatasetRefFromReq examines the path element of a request URL to
func HTTPPathToQriPath ¶ added in v0.1.2
HTTPPathToQriPath converts a http path to a qri path
func HTTPSRedirect ¶
func HTTPSRedirect()
HTTPSRedirect listens on port 80, redirecting HTTP requests to https
func NewServerRoutes ¶
NewServerRoutes returns a Muxer that has all API routes
func StartServer ¶
StartServer interprets info from config to start the server if config.TLS == true it'll spin up an https server using LetsEncrypt that should work just fine on the raw internet (ie not behind a proxy like nginx etc) it'll also redirect http traffic to it's https route counterpart if port 80 is open
Types ¶
type Config ¶
type Config struct {
Logger logging.Logger
// operation mode
Mode string
// URLRoot is the base url for this server
URLRoot string
// DNS service discovery. Should be either "env" or "dns", default is env
GetHostsFrom string
// Public Key to use for signing metablocks. required.
PublicKey string
// TLS (HTTPS) enable support via LetsEncrypt, default false
// should be true in production
TLS bool
// support CORS signing from a list of origins
AllowedOrigins []string
// if true, requests that have X-Forwarded-Proto: http will be redirected
// to their https variant
ProxyForceHTTPS bool
// token for analytics tracking
AnalyticsToken string
// set to true to run entire server with in-memory structures
MemOnly bool
// disable networking
Online bool
// APIPort specifies the port to listen for JSON API calls
APIPort string
// RPCPort specifies the port to listen for RPC calls on, if empty server will not register a RPC listener
RPCPort string
// set to to disable webapp
WebappPort string
// list of addresses to bootsrap qri peers on
BoostrapAddrs []string
// WebappScripts is a list of script tags to include the webapp page, useful for using alternative / beta
// versions of the qri frontend
WebappScripts []string
// PostP2POnlineHook is a chance to call a function after starting P2P services
PostP2POnlineHook func(*p2p.QriNode)
}
Config holds all configuration for the server. It pulls from three places (in order):
- environment variables
- .[MODE].env OR .env
globally-set env variables win. it's totally fine to not have, say, .env.develop defined, and just rely on a base ".env" file. But if you're in production mode & ".env.production" exists, that will be read *instead* of .env
configuration is read at startup and cannot be alterd without restarting the server.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns the default configuration details
type DataResponse ¶ added in v0.2.0
type DataResponse struct {
Path string `json:"path"`
Data json.RawMessage `json:"data"`
}
DataResponse is the struct used to respond to api requests made to the /data endpoint It is necessary because we need to include the 'path' field in the response
type DatasetHandlers ¶ added in v0.1.2
type DatasetHandlers struct {
core.DatasetRequests
// contains filtered or unexported fields
}
DatasetHandlers wraps a requests struct to interface with http.HandlerFunc
func NewDatasetHandlers ¶ added in v0.1.2
func NewDatasetHandlers(log logging.Logger, r repo.Repo) *DatasetHandlers
NewDatasetHandlers allocates a DatasetHandlers pointer
func (*DatasetHandlers) AddHandler ¶ added in v0.1.2
func (h *DatasetHandlers) AddHandler(w http.ResponseWriter, r *http.Request)
AddHandler is an endpoint for creating new datasets
func (*DatasetHandlers) DataHandler ¶ added in v0.2.0
func (h *DatasetHandlers) DataHandler(w http.ResponseWriter, r *http.Request)
DataHandler gets a dataset's data
func (*DatasetHandlers) DiffHandler ¶ added in v0.2.0
func (h *DatasetHandlers) DiffHandler(w http.ResponseWriter, r *http.Request)
DiffHandler is a dataset single endpoint
func (*DatasetHandlers) GetHandler ¶ added in v0.1.2
func (h *DatasetHandlers) GetHandler(w http.ResponseWriter, r *http.Request)
GetHandler is a dataset single endpoint
func (*DatasetHandlers) InitHandler ¶ added in v0.1.2
func (h *DatasetHandlers) InitHandler(w http.ResponseWriter, r *http.Request)
InitHandler is an endpoint for creating new datasets
func (*DatasetHandlers) ListHandler ¶ added in v0.1.2
func (h *DatasetHandlers) ListHandler(w http.ResponseWriter, r *http.Request)
ListHandler is a dataset list endpoint
func (*DatasetHandlers) PeerListHandler ¶ added in v0.1.2
func (h *DatasetHandlers) PeerListHandler(w http.ResponseWriter, r *http.Request)
PeerListHandler is a dataset list endpoint
func (*DatasetHandlers) RemoveHandler ¶ added in v0.1.2
func (h *DatasetHandlers) RemoveHandler(w http.ResponseWriter, r *http.Request)
RemoveHandler is a a dataset delete endpoint
func (*DatasetHandlers) RenameHandler ¶ added in v0.1.2
func (h *DatasetHandlers) RenameHandler(w http.ResponseWriter, r *http.Request)
RenameHandler is the endpoint for renaming datasets
func (*DatasetHandlers) SaveHandler ¶ added in v0.1.2
func (h *DatasetHandlers) SaveHandler(w http.ResponseWriter, r *http.Request)
SaveHandler is a dataset save/update endpoint
func (*DatasetHandlers) ZipDatasetHandler ¶ added in v0.1.2
func (h *DatasetHandlers) ZipDatasetHandler(w http.ResponseWriter, r *http.Request)
ZipDatasetHandler is the endpoint for getting a zip archive of a dataset
type HistoryHandlers ¶ added in v0.1.2
type HistoryHandlers struct {
core.HistoryRequests
// contains filtered or unexported fields
}
HistoryHandlers wraps a HistoryRequests with http.HandlerFuncs
func NewHistoryHandlers ¶ added in v0.1.2
func NewHistoryHandlers(log logging.Logger, r repo.Repo) *HistoryHandlers
NewHistoryHandlers allocates a HistoryHandlers pointer
func (*HistoryHandlers) LogHandler ¶ added in v0.1.2
func (h *HistoryHandlers) LogHandler(w http.ResponseWriter, r *http.Request)
LogHandler is the endpoint for dataset logs
type PeerHandlers ¶ added in v0.1.2
type PeerHandlers struct {
core.PeerRequests
// contains filtered or unexported fields
}
PeerHandlers wraps a requests struct to interface with http.HandlerFunc
func NewPeerHandlers ¶ added in v0.1.2
NewPeerHandlers allocates a PeerHandlers pointer
func (*PeerHandlers) ConnectToPeerHandler ¶ added in v0.2.0
func (h *PeerHandlers) ConnectToPeerHandler(w http.ResponseWriter, r *http.Request)
ConnectToPeerHandler is the endpoint for explicitly connecting to a peer
func (*PeerHandlers) ConnectionsHandler ¶ added in v0.1.2
func (h *PeerHandlers) ConnectionsHandler(w http.ResponseWriter, r *http.Request)
ConnectionsHandler is the endpoint for listing qri & IPFS connections
func (*PeerHandlers) PeerHandler ¶ added in v0.2.0
func (h *PeerHandlers) PeerHandler(w http.ResponseWriter, r *http.Request)
PeerHandler gets info on a single peer
func (*PeerHandlers) PeersHandler ¶ added in v0.1.2
func (h *PeerHandlers) PeersHandler(w http.ResponseWriter, r *http.Request)
PeersHandler is the endpoint for fetching peers
type ProfileHandlers ¶ added in v0.1.2
type ProfileHandlers struct {
core.ProfileRequests
// contains filtered or unexported fields
}
ProfileHandlers wraps a requests struct to interface with http.HandlerFunc
func NewProfileHandlers ¶ added in v0.1.2
func NewProfileHandlers(log logging.Logger, r repo.Repo) *ProfileHandlers
NewProfileHandlers allocates a ProfileHandlers pointer
func (*ProfileHandlers) ProfileHandler ¶ added in v0.1.2
func (h *ProfileHandlers) ProfileHandler(w http.ResponseWriter, r *http.Request)
ProfileHandler is the endpoint for this peer's profile
func (*ProfileHandlers) SetPosterHandler ¶ added in v0.1.2
func (h *ProfileHandlers) SetPosterHandler(w http.ResponseWriter, r *http.Request)
SetPosterHandler is the endpoint for uploading this peer's poster photo
func (*ProfileHandlers) SetProfilePhotoHandler ¶ added in v0.1.2
func (h *ProfileHandlers) SetProfilePhotoHandler(w http.ResponseWriter, r *http.Request)
SetProfilePhotoHandler is the endpoint for uploading this peer's profile photo
type QriCtxKey ¶ added in v0.1.2
type QriCtxKey string
QriCtxKey defines a distinct type for keys for context values should always use custom types to avoid collissions. see comment on context.WithValue for more info
const DatasetRefCtxKey QriCtxKey = "datasetRef"
DatasetRefCtxKey is the key for adding a dataset reference to a context.Context
type RenameReqParams ¶ added in v0.1.2
RenameReqParams is an encoding struct its intent is to be a more user-friendly structure for the api endpoint that will map to and from the core.RenameParams struct
type RootHandler ¶ added in v0.1.2
type RootHandler struct {
// contains filtered or unexported fields
}
RootHandler bundles handlers that may need to be called by "/" TODO - This will be removed when we add a proper router
func NewRootHandler ¶ added in v0.1.2
func NewRootHandler(dsh *DatasetHandlers, ph *PeerHandlers) *RootHandler
NewRootHandler creates a new RootHandler
func (*RootHandler) Handler ¶ added in v0.1.2
func (mh *RootHandler) Handler(w http.ResponseWriter, r *http.Request)
Handler is the only Handler func for the RootHandler struct
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps a qri p2p node, providing traditional access via http Create one with New, start it up with Serve
func New ¶
New creates a new qri server with optional configuration calling New() with no options will return the default configuration as specified in DefaultConfig
func (*Server) HandleIPFSPath ¶
func (s *Server) HandleIPFSPath(w http.ResponseWriter, r *http.Request)
HandleIPFSPath responds to IPFS Hash requests with raw data
func (*Server) HandleIPNSPath ¶ added in v0.2.0
func (s *Server) HandleIPNSPath(w http.ResponseWriter, r *http.Request)
HandleIPNSPath resolves an IPNS entry
func (*Server) ServeRPC ¶
func (s *Server) ServeRPC()
ServeRPC checks for a configured RPC port, and registers a listner if so
func (*Server) ServeWebapp ¶ added in v0.2.0
func (s *Server) ServeWebapp()
ServeWebapp launches a webapp server on s.cfg.WebappPort
func (*Server) WebappHandler ¶ added in v0.2.0
func (s *Server) WebappHandler(w http.ResponseWriter, r *http.Request)
WebappHandler renders the home page