Fix read yaml config from memory

package main

import (
	"fmt"

	"github.com/micro/go-micro/config"
	"github.com/micro/go-micro/config/source/memory"
)

var configData = []byte(`
---
a: 1234
`)

func main() {
	memorySource := memory.NewSource(
		memory.WithYAML(configData),
	)
	// Create new config
	conf := config.NewConfig()

	// Load file source
	conf.Load(memorySource)

	fmt.Println(string(conf.Bytes()))
}
This commit is contained in:
刘小乐 2019-08-11 18:05:35 +08:00 committed by GitHub
parent e613b0c205
commit cd2ac648ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,6 +18,7 @@ type memory struct {
func (s *memory) Read() (*source.ChangeSet, error) { func (s *memory) Read() (*source.ChangeSet, error) {
s.RLock() s.RLock()
cs := &source.ChangeSet{ cs := &source.ChangeSet{
Format: s.ChangeSet.Format,
Timestamp: s.ChangeSet.Timestamp, Timestamp: s.ChangeSet.Timestamp,
Data: s.ChangeSet.Data, Data: s.ChangeSet.Data,
Checksum: s.ChangeSet.Checksum, Checksum: s.ChangeSet.Checksum,