feat(blogo,plugins,empty-sourcer): rename and export defaultSourcer as emptySourcer

This commit is contained in:
Guz
2025-01-13 16:27:59 -03:00
parent c46bb3042f
commit a2e92a2ba3
3 changed files with 49 additions and 18 deletions

View File

@@ -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 {

View File

@@ -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 {

View 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
}