GoBlog/pkgs/plugintypes/app.go

63 lines
1.8 KiB
Go

package plugintypes
import (
"context"
"database/sql"
"io"
"net/http"
)
// App is used to access GoBlog's app instance.
type App interface {
// Get access to GoBlog's database
GetDatabase() Database
// Get a post from the database or an error when there is no post for the given path
GetPost(path string) (Post, error)
// Purge the rendering cache
PurgeCache()
// Get the HTTP client used by GoBlog
GetHTTPClient() *http.Client
// Compile an asset (like CSS, JS, etc.) and add it to use when rendering, for some filetypes, it also get's compressed
CompileAsset(filename string, reader io.Reader) error
// Get the asset path with the filename used when compiling the assert
AssetPath(filename string) string
}
// Database is used to provide access to GoBlog's database.
type Database interface {
Exec(string, ...any) (sql.Result, error)
ExecContext(context.Context, string, ...any) (sql.Result, error)
Query(string, ...any) (*sql.Rows, error)
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
QueryRow(string, ...any) (*sql.Row, error)
QueryRowContext(context.Context, string, ...any) (*sql.Row, error)
}
// Post
type Post interface {
// Get the post path
GetPath() string
// Get a string array map with all the post's parameters
GetParameters() map[string][]string
// Get a single parameter array (a parameter can have multiple values)
GetParameter(parameter string) []string
// Get the post section name
GetSection() string
// Get the published date string
GetPublished() string
// Get the updated date string
GetUpdated() string
// Get the post content (markdown)
GetContent() string
}
// RenderContext
type RenderContext interface {
// Get the path of the request
GetPath() string
// Get the URL
GetURL() string
// Get the blog name
GetBlog() string
}