Create Your Own Store
Follow these steps to create a new store package using the recommended patterns.
1. Define Constants
Create a constants.go
file for all statuses, types, and configuration values. Use UPPER_SNAKE_CASE for public, lowerCamelCase for private constants.
2. Define Private Structs & Public Interfaces
Make all entity structs private. Define a public interface for all operations (getters, setters, meta, etc.).
3. Embed DataObject
Embed a DataObject in your struct for generic data handling. Provide constructors for new and existing data.
4. Design SQL Schema
Use Goqu or a similar builder to define your schema. Implement AutoMigrate for setup and updates. Support multiple SQL drivers.
5. Implement Store Layer
Create a StoreInterface for CRUD and queries. Implement a concrete store struct. Organize methods by entity.
6. Write Tests
Test using real in-memory SQLite databases. Avoid mocks. Use interfaces for flexibility.
Checklist
- Constants defined
- Private entity struct
- Public interface
- DataObject embedded
- SQL schema ready
- Store layer implemented
- Tests written