This is a GO API template with MUX where the backend database is POCKETBASE. This is just for testing purpose.
go_api_pocketbase_template
|
|--pocketbase_0.22.12_linux_amd64 # The Pocketbase executable
|--routes
| |--routes.go # Go file for defining routes
|
|--types
| |--types.go # Go file for defining types
|
|--go.mod # Go module file
|--go.sum # Go dependencies checksum file
|--main_test.go # Testing file
|--main.go # Main entry point of the Go application
|--README.md # Documentation filecd pocketbase_0.22.12_linux_amd64 && ./pocketbase serve
Click on the Admin UI: http://127.0.0.1:8090/_/
Username:[email protected]
Password:0123456789
Note: You can also download pocketbase_0.22.12_linux_amd64 from https://pocketbase.io/docs/ and extract it on the file structure provided above.
go run main.go
You can also specify port number
go run main.go --listenAddr :2000
go mod init go_api_pocketbase_template
go mod tidyUse postman or thunder client for testing the endpoints
Sure, here are all the endpoints summarized in six lines:
- GET
/- Check server status (routes.Hello) -http://localhost:3000/ - GET
/posts- Retrieve all posts (routes.GetPosts) -http://localhost:3000/posts - POST
/posts- Create a new post (routes.CreatePost) -http://localhost:3000/posts - GET
/posts/{id}- Retrieve a post by ID (routes.GetPost) -http://localhost:3000/posts/{id} - PUT
/posts/{id}- Update a post by ID (routes.UpdatePost) -http://localhost:3000/posts/{id} - DELETE
/posts/{id}- Delete a post by ID (routes.DeletePost) -http://localhost:3000/posts/{id}
You can config the pocketbase url and endpoint on routes/routes.go on line 15,16.
To run your application with a custom listening address:
go run main.go --listenAddr :2000To run the tests locally:
go test -v ./...Testing the main app
go test -v main_test.goRunning the pocketbase server.
cd pocketbase_0.22.12_linux_amd64 && ./pocketbase serve
Testing the pocketbase server
go test -v server_test.go