Documentation
¶
Index ¶
- Variables
- func AssetHandler() http.Handler
- func DevAssetHandler(path, dir string) http.Handler
- func GetClientErrorStatusPage(_ *weburl.GnoURL, err error) (int, *components.View)
- func IsHomePath(path string) bool
- func NewRouter(logger *slog.Logger, cfg *AppConfig) (http.Handler, error)
- func RedirectMiddleware(next http.Handler, analytics bool) http.Handler
- type AliasKind
- type AliasTarget
- type AppConfig
- type ContentRenderer
- type FileMeta
- type HTMLWebClient
- func (s *HTMLWebClient) Doc(pkgPath string) (*doc.JSONDocumentation, error)
- func (s *HTMLWebClient) FormatSource(w io.Writer, fileName string, src []byte) error
- func (s *HTMLWebClient) QueryPaths(prefix string, limit int) ([]string, error)
- func (s *HTMLWebClient) RenderRealm(w io.Writer, u *weburl.GnoURL, cr ContentRenderer) (*RealmMeta, error)
- func (s *HTMLWebClient) SourceFile(w io.Writer, path, fileName string, isRaw bool) (*FileMeta, error)
- func (s *HTMLWebClient) Sources(path string) ([]string, error)
- func (s *HTMLWebClient) WriteFormatterCSS(w io.Writer) error
- type HTMLWebClientConfig
- type MarkdownRenderer
- type MarkdownRendererConfig
- type MockPackage
- type MockWebClient
- func (m *MockWebClient) Doc(path string) (*doc.JSONDocumentation, error)
- func (m *MockWebClient) QueryPaths(prefix string, limit int) ([]string, error)
- func (m *MockWebClient) RenderRealm(w io.Writer, u *weburl.GnoURL, _ ContentRenderer) (*RealmMeta, error)
- func (m *MockWebClient) SourceFile(w io.Writer, pkgPath, fileName string, isRaw bool) (*FileMeta, error)
- func (m *MockWebClient) Sources(path string) ([]string, error)
- 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, indexData *components.IndexData) (int, *components.View)
- func (h *WebHandler) GetHelpView(gnourl *weburl.GnoURL) (int, *components.View)
- func (h *WebHandler) GetMarkdownView(gnourl *weburl.GnoURL, mdContent string) (int, *components.View)
- func (h *WebHandler) GetPackageView(gnourl *weburl.GnoURL, indexData *components.IndexData) (int, *components.View)
- func (h *WebHandler) GetPathsListView(gnourl *weburl.GnoURL, indexData *components.IndexData) (int, *components.View)
- func (h *WebHandler) GetRealmView(gnourl *weburl.GnoURL, indexData *components.IndexData) (int, *components.View)
- func (h *WebHandler) GetSourceDownload(gnourl *weburl.GnoURL, w http.ResponseWriter, r *http.Request)
- 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 DefaultAliases = map[string]AliasTarget{ "/": {"/r/gnoland/home", GnowebPath}, "/about": {"/r/gnoland/pages:p/about", GnowebPath}, "/gnolang": {"/r/gnoland/pages:p/gnolang", GnowebPath}, "/ecosystem": {"/r/gnoland/pages:p/ecosystem", GnowebPath}, "/start": {"/r/gnoland/pages:p/start", GnowebPath}, "/license": {"/r/gnoland/pages:p/license", GnowebPath}, "/contribute": {"/r/gnoland/pages:p/contribute", GnowebPath}, "/events": {"/r/gnoland/events", GnowebPath}, }
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",
}
redirects are gnoweb paths that are redirected using [AliasAndRedirectMiddleware].
Functions ¶
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 ¶
func IsHomePath ¶
IsHomePath checks if the given path is the home path.
Types ¶
type AliasTarget ¶
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 // Aliases is a map of aliases pointing to another path or a static file. Aliases map[string]AliasTarget }
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 ContentRenderer ¶
type ContentRenderer interface { // Render renders the content of a source file and write it on the given writer. // It returns a Table of Contents (Toc) and an error if any occurs. Render(w io.Writer, u *weburl.GnoURL, src []byte) (md.Toc, error) }
Renderer is an interface for rendering content from source.
type HTMLWebClient ¶
type HTMLWebClient struct { 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) Doc ¶
func (s *HTMLWebClient) Doc(pkgPath string) (*doc.JSONDocumentation, error)
Doc retrieves the JSON doc suitable for printing from a specified package path.
func (*HTMLWebClient) FormatSource ¶
func (*HTMLWebClient) QueryPaths ¶
func (s *HTMLWebClient) QueryPaths(prefix string, limit int) ([]string, error)
Sources lists all source files available in a specified package path by querying the RPC client.
func (*HTMLWebClient) RenderRealm ¶
func (s *HTMLWebClient) RenderRealm(w io.Writer, u *weburl.GnoURL, cr ContentRenderer) (*RealmMeta, error)
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 ¶
func (s *HTMLWebClient) SourceFile(w io.Writer, path, fileName string, isRaw bool) (*FileMeta, error)
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 or Raw style 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 }
func NewDefaultHTMLWebClientConfig ¶
func NewDefaultHTMLWebClientConfig(client *client.RPCClient) *HTMLWebClientConfig
NewDefaultHTMLWebClientConfig initializes a WebClientConfig with default settings.
type MarkdownRenderer ¶
type MarkdownRenderer struct {
// contains filtered or unexported fields
}
func NewMarkdownRenderer ¶
func NewMarkdownRenderer(logger *slog.Logger, cfg *MarkdownRendererConfig) *MarkdownRenderer
type MarkdownRendererConfig ¶
func NewDefaultMarkdownRendererConfig ¶
func NewDefaultMarkdownRendererConfig(chromaOptions []chromahtml.Option) *MarkdownRendererConfig
type MockPackage ¶
type MockPackage struct { Path string Domain string Files map[string]string // filename -> body Functions []*doc.JSONFunc }
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) Doc ¶
func (m *MockWebClient) Doc(path string) (*doc.JSONDocumentation, error)
Doc simulates retrieving function docs from a package.
func (*MockWebClient) QueryPaths ¶
func (m *MockWebClient) QueryPaths(prefix string, limit int) ([]string, error)
Sources simulates listing all source files in a package.
func (*MockWebClient) RenderRealm ¶
func (m *MockWebClient) RenderRealm(w io.Writer, u *weburl.GnoURL, _ ContentRenderer) (*RealmMeta, error)
RenderRealm simulates rendering a package by writing its content to the writer.
func (*MockWebClient) SourceFile ¶
func (m *MockWebClient) SourceFile(w io.Writer, pkgPath, fileName string, isRaw bool) (*FileMeta, error)
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, u *weburl.GnoURL, cr ContentRenderer) (*RealmMeta, error) // SourceFile fetches and writes the source file from a given // package path, file name and if raw. The method should ensures the source // file's content is safely handled and formatted. SourceFile(w io.Writer, pkgPath, fileName string, isRaw bool) (*FileMeta, error) // QueryPath list any path given the specified prefix QueryPaths(prefix string, limit int) ([]string, error) // Doc retrieves the JSON doc suitable for printing from a // specified package path. Doc(path string) (*doc.JSONDocumentation, 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 MarkdownRenderer *MarkdownRenderer Aliases map[string]AliasTarget }
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, indexData *components.IndexData) (int, *components.View)
func (*WebHandler) GetHelpView ¶
func (h *WebHandler) GetHelpView(gnourl *weburl.GnoURL) (int, *components.View)
func (*WebHandler) GetMarkdownView ¶
func (h *WebHandler) GetMarkdownView(gnourl *weburl.GnoURL, mdContent string) (int, *components.View)
GetMarkdownView handles markdown files.
func (*WebHandler) GetPackageView ¶
func (h *WebHandler) GetPackageView(gnourl *weburl.GnoURL, indexData *components.IndexData) (int, *components.View)
GetPackageView handles package pages.
func (*WebHandler) GetPathsListView ¶
func (h *WebHandler) GetPathsListView(gnourl *weburl.GnoURL, indexData *components.IndexData) (int, *components.View)
func (*WebHandler) GetRealmView ¶
func (h *WebHandler) GetRealmView(gnourl *weburl.GnoURL, indexData *components.IndexData) (int, *components.View)
func (*WebHandler) GetSourceDownload ¶
func (h *WebHandler) GetSourceDownload(gnourl *weburl.GnoURL, w http.ResponseWriter, r *http.Request)
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 MarkdownRenderer *MarkdownRenderer Aliases map[string]AliasTarget }
WebHandlerConfig configures a WebHandler.