Documentation
¶
Overview ¶
Package native implements the knowledge package's v2 routes in the package itself. The package adopts the kernel's v2_knowledge table (kernel.storage.adopt:v2_knowledge), so the native routes and the kernel's legacy handlers read and write the same rows: switching a route between legacy and native needs no data move and can be undone at any time. Responses are byte-compatible with the legacy handlers (internal/tests/knowledgecompat).
Index ¶
- type Article
- type Service
- func (s *Service) AdminCreate(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
- func (s *Service) AdminDelete(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
- func (s *Service) AdminList(ctx context.Context, _ pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
- func (s *Service) AdminUpdate(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
- func (s *Service) Handlers() map[string]pluginhostsdk.NativeHandler
- func (s *Service) UserGet(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
- func (s *Service) UserList(ctx context.Context, _ pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Article ¶
type Article struct {
ID uint `gorm:"primaryKey" json:"id"`
Category string `gorm:"size:64" json:"category"`
Title string `gorm:"size:255" json:"title"`
Body string `gorm:"type:text" json:"body"`
Sort int `gorm:"default:0" json:"sort"`
Show int `gorm:"default:1" json:"show"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Article is a v2_knowledge row. Its JSON matches the kernel model, which the admin create answer returns as is.
type Service ¶
type Service struct {
// Open returns the package's storage connection, on which the adopted
// v2_knowledge table is visible.
Open func(ctx context.Context) (*gorm.DB, error)
// Now defaults to time.Now.
Now func() time.Time
}
Service holds what the native routes need.
func (*Service) AdminCreate ¶
func (s *Service) AdminCreate(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
AdminCreate is POST /api/v2/admin/knowledge.
func (*Service) AdminDelete ¶
func (s *Service) AdminDelete(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
AdminDelete is DELETE /api/v2/admin/knowledge/:id.
func (*Service) AdminList ¶
func (s *Service) AdminList(ctx context.Context, _ pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
AdminList is GET /api/v2/admin/knowledge.
func (*Service) AdminUpdate ¶
func (s *Service) AdminUpdate(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
AdminUpdate is PUT /api/v2/admin/knowledge/:id.
func (*Service) Handlers ¶
func (s *Service) Handlers() map[string]pluginhostsdk.NativeHandler
Handlers returns the native handlers by route id.
func (*Service) UserGet ¶
func (s *Service) UserGet(ctx context.Context, request pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
UserGet is GET /api/v2/user/knowledge/:id.
func (*Service) UserList ¶
func (s *Service) UserList(ctx context.Context, _ pluginhostsdk.NativeRequest) (pluginhostsdk.NativeResponse, error)
UserList is GET /api/v2/user/knowledge: visible articles.