Documentation
¶
Index ¶
- Variables
- func AliasAndRedirectMiddleware(next http.Handler, analytics bool) http.Handler
- func AssetHandler() http.Handler
- func DevAssetHandler(path, dir string) http.Handler
- func GetClientErrorStatusPage(_ *weburl.GnoURL, err error) (int, *components.View)
- func NewRouter(logger *slog.Logger, cfg *AppConfig) (http.Handler, error)
- type AppConfig
- type FileMeta
- type HTMLWebClient
- func (s *HTMLWebClient) FormatSource(w io.Writer, fileName string, src []byte) error
- func (s *HTMLWebClient) Functions(pkgPath string) ([]vm.FunctionSignature, error)
- func (s *HTMLWebClient) RenderRealm(w io.Writer, pkgPath string, args string) (*RealmMeta, error)
- func (s *HTMLWebClient) SourceFile(w io.Writer, path, fileName string) (*FileMeta, error)
- func (s *HTMLWebClient) Sources(path string) ([]string, error)
- func (s *HTMLWebClient) WriteFormatterCSS(w io.Writer) error
- type HTMLWebClientConfig
- type MockPackage
- type MockWebClient
- func (m *MockWebClient) Functions(path string) ([]vm.FunctionSignature, error)
- func (m *MockWebClient) RenderRealm(w io.Writer, path string, args string) (*RealmMeta, error)
- func (m *MockWebClient) SourceFile(w io.Writer, pkgPath, fileName string) (*FileMeta, error)
- func (m *MockWebClient) Sources(path string) ([]string, error)
- type PageData
- type RealmMeta
- type StaticMetadata
- type WebClient
- type WebHandler
- func (h *WebHandler) Get(w http.ResponseWriter, r *http.Request)
- func (h *WebHandler) GetDirectoryView(gnourl *weburl.GnoURL) (int, *components.View)
- func (h *WebHandler) GetHelpView(gnourl *weburl.GnoURL) (int, *components.View)
- func (h *WebHandler) GetPackageView(gnourl *weburl.GnoURL) (int, *components.View)
- func (h *WebHandler) GetRealmView(gnourl *weburl.GnoURL) (int, *components.View)
- func (h *WebHandler) GetSourceView(gnourl *weburl.GnoURL) (int, *components.View)
- func (h *WebHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
- type WebHandlerConfig
Constants ¶
This section is empty.
Variables ¶
var ( ErrClientPathNotFound = errors.New("package not found") ErrRenderNotDeclared = errors.New("render function not declared") ErrClientBadRequest = errors.New("bad request") ErrClientResponse = errors.New("node response error") )
var Aliases = map[string]string{
"/": "/r/gnoland/home",
"/about": "/r/gnoland/pages:p/about",
"/gnolang": "/r/gnoland/pages:p/gnolang",
"/ecosystem": "/r/gnoland/pages:p/ecosystem",
"/partners": "/r/gnoland/pages:p/partners",
"/testnets": "/r/gnoland/pages:p/testnets",
"/start": "/r/gnoland/pages:p/start",
"/license": "/r/gnoland/pages:p/license",
"/contribute": "/r/gnoland/pages:p/contribute",
"/events": "/r/gnoland/events",
}
Aliases are gnoweb paths that are rewritten using AliasAndRedirectMiddleware.
var Redirects = map[string]string{
"/r/demo/boards:gnolang/6": "/r/demo/boards:gnolang/3",
"/blog": "/r/gnoland/blog",
"/gor": "/contribute",
"/game-of-realms": "/contribute",
"/grants": "/partners",
"/language": "/gnolang",
"/getting-started": "/start",
}
Redirect are gnoweb paths that are redirected using AliasAndRedirectMiddleware.
Functions ¶
func AliasAndRedirectMiddleware ¶
AliasAndRedirectMiddleware redirects all incoming requests whose path matches any of the Redirects to the corresponding URL; and rewrites the URL path for incoming requests which match any of the Aliases.
func AssetHandler ¶
AssetHandler returns the handler to serve static assets. If cache is true, these will be served using the static files embedded in the binary; otherwise they will served from the filesystem.
func DevAssetHandler ¶
Types ¶
type AppConfig ¶
type AppConfig struct { // UnsafeHTML, if enabled, allows to use HTML in the markdown. UnsafeHTML bool // Analytics enables SimpleAnalytics. Analytics bool // NodeRemote is the remote address of the gno.land node. NodeRemote string // RemoteHelp is the remote of the gno.land node, as used in the help page. RemoteHelp string // ChainID is the chain id, used for constructing the help page. ChainID string // AssetsPath is the base path to the gnoweb assets. AssetsPath string // AssetDir, if set, will be used for assets instead of the embedded public directory. AssetsDir string // FaucetURL, if specified, will be the URL to which `/faucet` redirects. FaucetURL string // Domain is the domain used by the node. Domain string }
AppConfig contains configuration for the gnoweb.
func NewDefaultAppConfig ¶
func NewDefaultAppConfig() *AppConfig
NewDefaultAppConfig returns a new default AppConfig. The default sets 127.0.0.1:26657 as the remote node, "dev" as the chain ID and sets up Assets to be served on /public/.
type HTMLWebClient ¶
type HTMLWebClient struct { Markdown goldmark.Markdown Formatter *chromahtml.Formatter // contains filtered or unexported fields }
func NewHTMLClient ¶
func NewHTMLClient(log *slog.Logger, cfg *HTMLWebClientConfig) *HTMLWebClient
NewHTMLClient creates a new instance of WebClient. It requires a configured logger and WebClientConfig.
func (*HTMLWebClient) FormatSource ¶
func (*HTMLWebClient) Functions ¶
func (s *HTMLWebClient) Functions(pkgPath string) ([]vm.FunctionSignature, error)
Functions retrieves a list of function signatures from a specified package path.
func (*HTMLWebClient) RenderRealm ¶
RenderRealm renders the content of a realm from a given path and arguments into the provided writer. It uses Goldmark for Markdown processing to generate HTML content.
func (*HTMLWebClient) SourceFile ¶
SourceFile fetches and writes the source file from a given package path and file name to the provided writer. It uses Chroma for syntax highlighting source.
func (*HTMLWebClient) Sources ¶
func (s *HTMLWebClient) Sources(path string) ([]string, error)
Sources lists all source files available in a specified package path by querying the RPC client.
func (*HTMLWebClient) WriteFormatterCSS ¶
func (s *HTMLWebClient) WriteFormatterCSS(w io.Writer) error
type HTMLWebClientConfig ¶
type HTMLWebClientConfig struct { Domain string RPCClient *client.RPCClient ChromaStyle *chroma.Style ChromaHTMLOptions []chromahtml.Option GoldmarkOptions []goldmark.Option }
func NewDefaultHTMLWebClientConfig ¶
func NewDefaultHTMLWebClientConfig(client *client.RPCClient) *HTMLWebClientConfig
NewDefaultHTMLWebClientConfig initializes a WebClientConfig with default settings. It sets up goldmark Markdown parsing options and default domain and highlighter.
type MockPackage ¶
type MockPackage struct { Path string Domain string Files map[string]string // filename -> body Functions []vm.FunctionSignature }
MockPackage represents a mock package with files and function signatures.
type MockWebClient ¶
type MockWebClient struct {
Packages map[string]*MockPackage // path -> package
}
MockWebClient is a mock implementation of the Client interface.
func NewMockWebClient ¶
func NewMockWebClient(pkgs ...*MockPackage) *MockWebClient
func (*MockWebClient) Functions ¶
func (m *MockWebClient) Functions(path string) ([]vm.FunctionSignature, error)
Functions simulates retrieving function signatures from a package.
func (*MockWebClient) RenderRealm ¶
RenderRealm simulates rendering a package by writing its content to the writer.
func (*MockWebClient) SourceFile ¶
SourceFile simulates retrieving a source file's metadata.
type StaticMetadata ¶
type StaticMetadata struct { Domain string AssetsPath string ChromaPath string RemoteHelp string ChainId string Analytics bool }
StaticMetadata holds static configuration for a web handler.
type WebClient ¶
type WebClient interface { // RenderRealm renders the content of a realm from a given path and // arguments into the giver `writer`. The method should ensures the rendered // content is safely handled and formatted. RenderRealm(w io.Writer, path string, args string) (*RealmMeta, error) // SourceFile fetches and writes the source file from a given // package path and file name. The method should ensures the source // file's content is safely handled and formatted. SourceFile(w io.Writer, pkgPath, fileName string) (*FileMeta, error) // Functions retrieves a list of function signatures from a // specified package path. Functions(path string) ([]vm.FunctionSignature, error) // Sources lists all source files available in a specified // package path. Sources(path string) ([]string, error) }
WebClient is an interface for interacting with package and node resources.
type WebHandler ¶
type WebHandler struct { Logger *slog.Logger Static StaticMetadata Client WebClient }
WebHandler processes HTTP requests.
func NewWebHandler ¶
func NewWebHandler(logger *slog.Logger, cfg WebHandlerConfig) (*WebHandler, error)
NewWebHandler creates a new WebHandler.
func (*WebHandler) Get ¶
func (h *WebHandler) Get(w http.ResponseWriter, r *http.Request)
Get processes a GET HTTP request.
func (*WebHandler) GetDirectoryView ¶
func (h *WebHandler) GetDirectoryView(gnourl *weburl.GnoURL) (int, *components.View)
func (*WebHandler) GetHelpView ¶
func (h *WebHandler) GetHelpView(gnourl *weburl.GnoURL) (int, *components.View)
func (*WebHandler) GetPackageView ¶
func (h *WebHandler) GetPackageView(gnourl *weburl.GnoURL) (int, *components.View)
GetPackageView handles package pages.
func (*WebHandler) GetRealmView ¶
func (h *WebHandler) GetRealmView(gnourl *weburl.GnoURL) (int, *components.View)
func (*WebHandler) GetSourceView ¶
func (h *WebHandler) GetSourceView(gnourl *weburl.GnoURL) (int, *components.View)
func (*WebHandler) ServeHTTP ¶
func (h *WebHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles HTTP requests.
type WebHandlerConfig ¶
type WebHandlerConfig struct { Meta StaticMetadata WebClient WebClient }
WebHandlerConfig configures a WebHandler.