mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-07 11:28:48 +03:00
Move Metadata load into NewMetadata function.
This commit is contained in:
parent
b97a7909d8
commit
e652d12cfc
6 changed files with 18 additions and 16 deletions
|
@ -122,7 +122,9 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
|
|||
return http.StatusInternalServerError, err
|
||||
}
|
||||
|
||||
// html, err = md.doTemplate(cfg, html, ctx)
|
||||
// TODO(weingart): move template execution here, something like:
|
||||
//
|
||||
// html, err = md.execTemplate(cfg, html, ctx)
|
||||
// if err != nil {
|
||||
// return http.StatusInternalServerError, err
|
||||
// }
|
||||
|
|
|
@ -32,6 +32,17 @@ type Metadata struct {
|
|||
Flags map[string]bool
|
||||
}
|
||||
|
||||
// NewMetadata() returns a new Metadata struct, loaded with the given map
|
||||
func NewMetadata(parsedMap map[string]interface{}) Metadata {
|
||||
md := Metadata{
|
||||
Variables: make(map[string]string),
|
||||
Flags: make(map[string]bool),
|
||||
}
|
||||
md.load(parsedMap)
|
||||
|
||||
return md
|
||||
}
|
||||
|
||||
// load loads parsed values in parsedMap into Metadata
|
||||
func (m *Metadata) load(parsedMap map[string]interface{}) {
|
||||
|
||||
|
@ -89,13 +100,6 @@ func GetParser(buf []byte) MetadataParser {
|
|||
return nil
|
||||
}
|
||||
|
||||
func NewMetadata() Metadata {
|
||||
return Metadata{
|
||||
Variables: make(map[string]string),
|
||||
Flags: make(map[string]bool),
|
||||
}
|
||||
}
|
||||
|
||||
// parsers returns all available parsers
|
||||
func parsers() []MetadataParser {
|
||||
return []MetadataParser{
|
||||
|
|
|
@ -36,8 +36,7 @@ func (j *JSONMetadataParser) Init(b *bytes.Buffer) bool {
|
|||
}
|
||||
}
|
||||
|
||||
j.metadata = NewMetadata()
|
||||
j.metadata.load(m)
|
||||
j.metadata = NewMetadata(m)
|
||||
j.markdown = bytes.NewBuffer(b.Bytes())
|
||||
|
||||
return true
|
||||
|
|
|
@ -17,8 +17,7 @@ func (n *NoneMetadataParser) Type() string {
|
|||
// Parse metadata/markdown file
|
||||
func (n *NoneMetadataParser) Init(b *bytes.Buffer) bool {
|
||||
m := make(map[string]interface{})
|
||||
n.metadata = NewMetadata()
|
||||
n.metadata.load(m)
|
||||
n.metadata = NewMetadata(m)
|
||||
n.markdown = bytes.NewBuffer(b.Bytes())
|
||||
|
||||
return true
|
||||
|
|
|
@ -28,8 +28,7 @@ func (t *TOMLMetadataParser) Init(b *bytes.Buffer) bool {
|
|||
if err := toml.Unmarshal(meta.Bytes(), &m); err != nil {
|
||||
return false
|
||||
}
|
||||
t.metadata = NewMetadata()
|
||||
t.metadata.load(m)
|
||||
t.metadata = NewMetadata(m)
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -27,8 +27,7 @@ func (y *YAMLMetadataParser) Init(b *bytes.Buffer) bool {
|
|||
if err := yaml.Unmarshal(meta.Bytes(), &m); err != nil {
|
||||
return false
|
||||
}
|
||||
y.metadata = NewMetadata()
|
||||
y.metadata.load(m)
|
||||
y.metadata = NewMetadata(m)
|
||||
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue