feat(blogo,plugins,empty-sourcer): rename and export defaultSourcer as emptySourcer
This commit is contained in:
@@ -25,8 +25,16 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// TODO: use binary operation so multiple levels can be used together
|
||||
// type PanicLevel int
|
||||
//
|
||||
// const (
|
||||
// PanicOnInit
|
||||
// )
|
||||
|
||||
type Options struct {
|
||||
Logger *slog.Logger
|
||||
// ErrorResponse TODO: structured error template or plugin
|
||||
}
|
||||
|
||||
type Blogo struct {
|
||||
@@ -138,8 +146,9 @@ func (b *Blogo) Init() error {
|
||||
log.Debug("Initializing blogo")
|
||||
|
||||
if len(b.sources) == 0 {
|
||||
log.Debug("No SourcerPlugin found, using default one")
|
||||
b.Use(&defaultSourcer{})
|
||||
sourcer := NewEmptySourcer()
|
||||
log.Debug(fmt.Sprintf("No SourcerPlugin found, using %q as fallback", sourcer.Name()))
|
||||
b.Use(sourcer)
|
||||
}
|
||||
|
||||
if len(b.renderers) == 0 {
|
||||
|
||||
@@ -7,22 +7,6 @@ import (
|
||||
"io/fs"
|
||||
)
|
||||
|
||||
type defaultSourcer struct{}
|
||||
|
||||
func (p *defaultSourcer) Name() string {
|
||||
return "blogo-sourcer-empty"
|
||||
}
|
||||
|
||||
func (p *defaultSourcer) Source() (fs.FS, error) {
|
||||
return emptyFS{}, nil
|
||||
}
|
||||
|
||||
type emptyFS struct{}
|
||||
|
||||
func (f emptyFS) Open(name string) (fs.File, error) {
|
||||
return nil, fs.ErrNotExist
|
||||
}
|
||||
|
||||
type painTextRenderer struct{}
|
||||
|
||||
func NewPlainTextRenderer() Plugin {
|
||||
|
||||
38
blogo/plugin_emptysourcer.go
Normal file
38
blogo/plugin_emptysourcer.go
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2025-present Gustavo "Guz" L. de Mello
|
||||
// Copyright 2025-present The Lored.dev Contributors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package blogo
|
||||
|
||||
import "io/fs"
|
||||
|
||||
type emptySourcer struct{}
|
||||
|
||||
func NewEmptySourcer() Plugin {
|
||||
return &emptySourcer{}
|
||||
}
|
||||
|
||||
func (p *emptySourcer) Name() string {
|
||||
return "blogo-empty-sourcer"
|
||||
}
|
||||
|
||||
func (p *emptySourcer) Source() (fs.FS, error) {
|
||||
return emptyFS{}, nil
|
||||
}
|
||||
|
||||
type emptyFS struct{}
|
||||
|
||||
func (f emptyFS) Open(name string) (fs.File, error) {
|
||||
return nil, fs.ErrNotExist
|
||||
}
|
||||
Reference in New Issue
Block a user