mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-30 17:53:21 -04:00 
			
		
		
		
	Drop caddy from vendor (#700)
* Removed caddy * new stuff * Now need to go get caddy * Duh
This commit is contained in:
		
							
								
								
									
										141
									
								
								vendor/github.com/go-openapi/swag/yaml.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										141
									
								
								vendor/github.com/go-openapi/swag/yaml.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -20,6 +20,9 @@ import ( | ||||
| 	"path/filepath" | ||||
| 	"strconv" | ||||
|  | ||||
| 	"github.com/mailru/easyjson/jlexer" | ||||
| 	"github.com/mailru/easyjson/jwriter" | ||||
|  | ||||
| 	yaml "gopkg.in/yaml.v2" | ||||
| ) | ||||
|  | ||||
| @@ -40,48 +43,150 @@ func YAMLToJSON(data interface{}) (json.RawMessage, error) { | ||||
| } | ||||
|  | ||||
| func BytesToYAMLDoc(data []byte) (interface{}, error) { | ||||
| 	var document map[interface{}]interface{} | ||||
| 	if err := yaml.Unmarshal(data, &document); err != nil { | ||||
| 	var canary map[interface{}]interface{} // validate this is an object and not a different type | ||||
| 	if err := yaml.Unmarshal(data, &canary); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
|  | ||||
| 	var document yaml.MapSlice // preserve order that is present in the document | ||||
| 	if err := yaml.Unmarshal(data, &document); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	return document, nil | ||||
| } | ||||
|  | ||||
| func transformData(in interface{}) (out interface{}, err error) { | ||||
| 	switch in.(type) { | ||||
| 	case map[interface{}]interface{}: | ||||
| 		o := make(map[string]interface{}) | ||||
| 		for k, v := range in.(map[interface{}]interface{}) { | ||||
| 			sk := "" | ||||
| 			switch k.(type) { | ||||
| type JSONMapSlice []JSONMapItem | ||||
|  | ||||
| func (s JSONMapSlice) MarshalJSON() ([]byte, error) { | ||||
| 	w := &jwriter.Writer{Flags: jwriter.NilMapAsEmpty | jwriter.NilSliceAsEmpty} | ||||
| 	s.MarshalEasyJSON(w) | ||||
| 	return w.BuildBytes() | ||||
| } | ||||
|  | ||||
| func (s JSONMapSlice) MarshalEasyJSON(w *jwriter.Writer) { | ||||
| 	w.RawByte('{') | ||||
|  | ||||
| 	ln := len(s) | ||||
| 	last := ln - 1 | ||||
| 	for i := 0; i < ln; i++ { | ||||
| 		s[i].MarshalEasyJSON(w) | ||||
| 		if i != last { // last item | ||||
| 			w.RawByte(',') | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	w.RawByte('}') | ||||
| } | ||||
|  | ||||
| func (s *JSONMapSlice) UnmarshalJSON(data []byte) error { | ||||
| 	l := jlexer.Lexer{Data: data} | ||||
| 	s.UnmarshalEasyJSON(&l) | ||||
| 	return l.Error() | ||||
| } | ||||
| func (s *JSONMapSlice) UnmarshalEasyJSON(in *jlexer.Lexer) { | ||||
| 	if in.IsNull() { | ||||
| 		in.Skip() | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	var result JSONMapSlice | ||||
| 	in.Delim('{') | ||||
| 	for !in.IsDelim('}') { | ||||
| 		var mi JSONMapItem | ||||
| 		mi.UnmarshalEasyJSON(in) | ||||
| 		result = append(result, mi) | ||||
| 	} | ||||
| 	*s = result | ||||
| } | ||||
|  | ||||
| type JSONMapItem struct { | ||||
| 	Key   string | ||||
| 	Value interface{} | ||||
| } | ||||
|  | ||||
| func (s JSONMapItem) MarshalJSON() ([]byte, error) { | ||||
| 	w := &jwriter.Writer{Flags: jwriter.NilMapAsEmpty | jwriter.NilSliceAsEmpty} | ||||
| 	s.MarshalEasyJSON(w) | ||||
| 	return w.BuildBytes() | ||||
| } | ||||
|  | ||||
| func (s JSONMapItem) MarshalEasyJSON(w *jwriter.Writer) { | ||||
| 	w.String(s.Key) | ||||
| 	w.RawByte(':') | ||||
| 	w.Raw(WriteJSON(s.Value)) | ||||
| } | ||||
|  | ||||
| func (s *JSONMapItem) UnmarshalEasyJSON(in *jlexer.Lexer) { | ||||
| 	key := in.UnsafeString() | ||||
| 	in.WantColon() | ||||
| 	value := in.Interface() | ||||
| 	in.WantComma() | ||||
| 	s.Key = key | ||||
| 	s.Value = value | ||||
| } | ||||
| func (s *JSONMapItem) UnmarshalJSON(data []byte) error { | ||||
| 	l := jlexer.Lexer{Data: data} | ||||
| 	s.UnmarshalEasyJSON(&l) | ||||
| 	return l.Error() | ||||
| } | ||||
|  | ||||
| func transformData(input interface{}) (out interface{}, err error) { | ||||
| 	switch in := input.(type) { | ||||
| 	case yaml.MapSlice: | ||||
|  | ||||
| 		o := make(JSONMapSlice, len(in)) | ||||
| 		for i, mi := range in { | ||||
| 			var nmi JSONMapItem | ||||
| 			switch k := mi.Key.(type) { | ||||
| 			case string: | ||||
| 				sk = k.(string) | ||||
| 				nmi.Key = k | ||||
| 			case int: | ||||
| 				sk = strconv.Itoa(k.(int)) | ||||
| 				nmi.Key = strconv.Itoa(k) | ||||
| 			default: | ||||
| 				return nil, fmt.Errorf("types don't match: expect map key string or int get: %T", k) | ||||
| 				return nil, fmt.Errorf("types don't match expect map key string or int got: %T", mi.Key) | ||||
| 			} | ||||
| 			v, err = transformData(v) | ||||
|  | ||||
| 			v, err := transformData(mi.Value) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 			o[sk] = v | ||||
| 			nmi.Value = v | ||||
| 			o[i] = nmi | ||||
| 		} | ||||
| 		return o, nil | ||||
| 	case map[interface{}]interface{}: | ||||
| 		o := make(JSONMapSlice, 0, len(in)) | ||||
| 		for ke, va := range in { | ||||
| 			var nmi JSONMapItem | ||||
| 			switch k := ke.(type) { | ||||
| 			case string: | ||||
| 				nmi.Key = k | ||||
| 			case int: | ||||
| 				nmi.Key = strconv.Itoa(k) | ||||
| 			default: | ||||
| 				return nil, fmt.Errorf("types don't match expect map key string or int got: %T", ke) | ||||
| 			} | ||||
|  | ||||
| 			v, err := transformData(va) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 			nmi.Value = v | ||||
| 			o = append(o, nmi) | ||||
| 		} | ||||
| 		return o, nil | ||||
| 	case []interface{}: | ||||
| 		in1 := in.([]interface{}) | ||||
| 		len1 := len(in1) | ||||
| 		len1 := len(in) | ||||
| 		o := make([]interface{}, len1) | ||||
| 		for i := 0; i < len1; i++ { | ||||
| 			o[i], err = transformData(in1[i]) | ||||
| 			o[i], err = transformData(in[i]) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 		} | ||||
| 		return o, nil | ||||
| 	} | ||||
| 	return in, nil | ||||
| 	return input, nil | ||||
| } | ||||
|  | ||||
| // YAMLDoc loads a yaml document from either http or a file and converts it to json | ||||
|   | ||||
							
								
								
									
										29
									
								
								vendor/github.com/go-openapi/swag/yaml_test.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										29
									
								
								vendor/github.com/go-openapi/swag/yaml_test.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -21,6 +21,8 @@ import ( | ||||
| 	"net/http/httptest" | ||||
| 	"testing" | ||||
|  | ||||
| 	yaml "gopkg.in/yaml.v2" | ||||
|  | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| @@ -56,34 +58,35 @@ func TestLoadHTTPBytes(t *testing.T) { | ||||
|  | ||||
| func TestYAMLToJSON(t *testing.T) { | ||||
|  | ||||
| 	data := make(map[interface{}]interface{}) | ||||
| 	data[1] = "the int key value" | ||||
| 	data["name"] = "a string value" | ||||
| 	data["y"] = "some value" | ||||
| 	sd := `--- | ||||
| 1: the int key value | ||||
| name: a string value | ||||
| 'y': some value | ||||
| ` | ||||
| 	var data yaml.MapSlice | ||||
| 	yaml.Unmarshal([]byte(sd), &data) | ||||
|  | ||||
| 	d, err := YAMLToJSON(data) | ||||
| 	if assert.NoError(t, err) { | ||||
| 		assert.Equal(t, `{"1":"the int key value","name":"a string value","y":"some value"}`, string(d)) | ||||
| 	} | ||||
|  | ||||
| 	data[true] = "the bool value" | ||||
| 	data = append(data, yaml.MapItem{Key: true, Value: "the bool value"}) | ||||
| 	d, err = YAMLToJSON(data) | ||||
| 	assert.Error(t, err) | ||||
| 	assert.Nil(t, d) | ||||
|  | ||||
| 	delete(data, true) | ||||
| 	data = data[:len(data)-1] | ||||
|  | ||||
| 	tag := make(map[interface{}]interface{}) | ||||
| 	tag["name"] = "tag name" | ||||
| 	data["tag"] = tag | ||||
| 	tag := yaml.MapSlice{{Key: "name", Value: "tag name"}} | ||||
| 	data = append(data, yaml.MapItem{Key: "tag", Value: tag}) | ||||
|  | ||||
| 	d, err = YAMLToJSON(data) | ||||
| 	assert.NoError(t, err) | ||||
| 	assert.Equal(t, `{"1":"the int key value","name":"a string value","tag":{"name":"tag name"},"y":"some value"}`, string(d)) | ||||
| 	assert.Equal(t, `{"1":"the int key value","name":"a string value","y":"some value","tag":{"name":"tag name"}}`, string(d)) | ||||
|  | ||||
| 	tag = make(map[interface{}]interface{}) | ||||
| 	tag[true] = "bool tag name" | ||||
| 	data["tag"] = tag | ||||
| 	tag = yaml.MapSlice{{Key: true, Value: "bool tag name"}} | ||||
| 	data = append(data[:len(data)-1], yaml.MapItem{Key: "tag", Value: tag}) | ||||
|  | ||||
| 	d, err = YAMLToJSON(data) | ||||
| 	assert.Error(t, err) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user