PocketBase can be used as regular Go package that exposes various helpers and hooks to help you implement you own custom business logic.
To get started:
- Install Go 1.21+
Create a new project directory with
main.go
file inside it. This is what an example PocketBase application looks like:package main import ( "log" "os" "github.com/pocketbase/pocketbase" "github.com/pocketbase/pocketbase/apis" "github.com/pocketbase/pocketbase/core" ) func main() { app := pocketbase.New() // serves static files from the provided public dir (if exists) app.OnBeforeServe().Add(func(e *core.ServeEvent) error { e.Router.GET("/*", apis.StaticDirectoryHandler(os.DirFS("./pb_public"), false)) return nil }) if err := app.Start(); err != nil { log.Fatal(err) } }
- To init the dependencies, run
go mod init myapp && go mod tidy
. - To start the application, run
go run main.go serve
. - To build a statically linked executable, you can run
CGO_ENABLED=0 go build
and then start the created executable with./myapp serve
.
PocketBase embeds SQLite, but doesn't require CGO.
If CGO is enabled (aka. CGO_ENABLED=1
), it will use
mattn/go-sqlite3
driver, otherwise the pure Go SQLite port -
modernc.org/sqlite
.
Enable CGO only if you really need to squeeze the query performance at the expense of complicating
cross compilation.