mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 01:02:25 -05:00 
			
		
		
		
	Import export (#194)
* start with export/import code * messing about with decoding/encoding * some more fiddling * stuff is WORKING * working pretty alright! * go fmt * fix up tests, add docs * start backup/restore doc * tweaks * credits * update advancedVisibility settings * update bun library -> v1.0.4 Signed-off-by: kim (grufwub) <grufwub@gmail.com> * update oauth library -> v4.3.1-SSB Signed-off-by: kim (grufwub) <grufwub@gmail.com> * handle oauth token scope, fix user.SigninCount + token.UserID Signed-off-by: kim (grufwub) <grufwub@gmail.com> * update oauth library --> v4.3.2-SSB Signed-off-by: kim (grufwub) <grufwub@gmail.com> * update sqlite library -> v1.13.0 Signed-off-by: kim (grufwub) <grufwub@gmail.com> * review changes * start with export/import code * messing about with decoding/encoding * some more fiddling * stuff is WORKING * working pretty alright! * go fmt * fix up tests, add docs * start backup/restore doc * tweaks * credits * update advancedVisibility settings * review changes Co-authored-by: kim (grufwub) <grufwub@gmail.com> Co-authored-by: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>
This commit is contained in:
		
					parent
					
						
							
								a027da0ac9
							
						
					
				
			
			
				commit
				
					
						555ea8edfb
					
				
			
		
					 61 changed files with 4031 additions and 250 deletions
				
			
		
							
								
								
									
										73
									
								
								vendor/github.com/mitchellh/mapstructure/CHANGELOG.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								vendor/github.com/mitchellh/mapstructure/CHANGELOG.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,73 @@ | |||
| ## unreleased | ||||
| 
 | ||||
| * Fix regression where `*time.Time` value would be set to empty and not be sent  | ||||
|   to decode hooks properly [GH-232] | ||||
| 
 | ||||
| ## 1.4.0 | ||||
| 
 | ||||
| * A new decode hook type `DecodeHookFuncValue` has been added that has | ||||
|   access to the full values. [GH-183] | ||||
| * Squash is now supported with embedded fields that are struct pointers [GH-205] | ||||
| * Empty strings will convert to 0 for all numeric types when weakly decoding [GH-206] | ||||
| 
 | ||||
| ## 1.3.3 | ||||
| 
 | ||||
| * Decoding maps from maps creates a settable value for decode hooks [GH-203] | ||||
| 
 | ||||
| ## 1.3.2 | ||||
| 
 | ||||
| * Decode into interface type with a struct value is supported [GH-187] | ||||
| 
 | ||||
| ## 1.3.1 | ||||
| 
 | ||||
| * Squash should only squash embedded structs. [GH-194] | ||||
| 
 | ||||
| ## 1.3.0 | ||||
| 
 | ||||
| * Added `",omitempty"` support. This will ignore zero values in the source | ||||
|   structure when encoding. [GH-145] | ||||
| 
 | ||||
| ## 1.2.3 | ||||
| 
 | ||||
| * Fix duplicate entries in Keys list with pointer values. [GH-185] | ||||
| 
 | ||||
| ## 1.2.2 | ||||
| 
 | ||||
| * Do not add unsettable (unexported) values to the unused metadata key | ||||
|   or "remain" value. [GH-150] | ||||
| 
 | ||||
| ## 1.2.1 | ||||
| 
 | ||||
| * Go modules checksum mismatch fix | ||||
| 
 | ||||
| ## 1.2.0 | ||||
| 
 | ||||
| * Added support to capture unused values in a field using the `",remain"` value | ||||
|   in the mapstructure tag. There is an example to showcase usage. | ||||
| * Added `DecoderConfig` option to always squash embedded structs | ||||
| * `json.Number` can decode into `uint` types | ||||
| * Empty slices are preserved and not replaced with nil slices | ||||
| * Fix panic that can occur in when decoding a map into a nil slice of structs | ||||
| * Improved package documentation for godoc | ||||
| 
 | ||||
| ## 1.1.2 | ||||
| 
 | ||||
| * Fix error when decode hook decodes interface implementation into interface | ||||
|   type. [GH-140] | ||||
| 
 | ||||
| ## 1.1.1 | ||||
| 
 | ||||
| * Fix panic that can happen in `decodePtr` | ||||
| 
 | ||||
| ## 1.1.0 | ||||
| 
 | ||||
| * Added `StringToIPHookFunc` to convert `string` to `net.IP` and `net.IPNet` [GH-133] | ||||
| * Support struct to struct decoding [GH-137] | ||||
| * If source map value is nil, then destination map value is nil (instead of empty) | ||||
| * If source slice value is nil, then destination slice value is nil (instead of empty) | ||||
| * If source pointer is nil, then destination pointer is set to nil (instead of | ||||
|   allocated zero value of type) | ||||
| 
 | ||||
| ## 1.0.0 | ||||
| 
 | ||||
| * Initial tagged stable release. | ||||
							
								
								
									
										21
									
								
								vendor/github.com/mitchellh/mapstructure/LICENSE
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								vendor/github.com/mitchellh/mapstructure/LICENSE
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,21 @@ | |||
| The MIT License (MIT) | ||||
| 
 | ||||
| Copyright (c) 2013 Mitchell Hashimoto | ||||
| 
 | ||||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||||
| of this software and associated documentation files (the "Software"), to deal | ||||
| in the Software without restriction, including without limitation the rights | ||||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||||
| copies of the Software, and to permit persons to whom the Software is | ||||
| furnished to do so, subject to the following conditions: | ||||
| 
 | ||||
| The above copyright notice and this permission notice shall be included in | ||||
| all copies or substantial portions of the Software. | ||||
| 
 | ||||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||||
| THE SOFTWARE. | ||||
							
								
								
									
										46
									
								
								vendor/github.com/mitchellh/mapstructure/README.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								vendor/github.com/mitchellh/mapstructure/README.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,46 @@ | |||
| # mapstructure [](https://godoc.org/github.com/mitchellh/mapstructure) | ||||
| 
 | ||||
| mapstructure is a Go library for decoding generic map values to structures | ||||
| and vice versa, while providing helpful error handling. | ||||
| 
 | ||||
| This library is most useful when decoding values from some data stream (JSON, | ||||
| Gob, etc.) where you don't _quite_ know the structure of the underlying data | ||||
| until you read a part of it. You can therefore read a `map[string]interface{}` | ||||
| and use this library to decode it into the proper underlying native Go | ||||
| structure. | ||||
| 
 | ||||
| ## Installation | ||||
| 
 | ||||
| Standard `go get`: | ||||
| 
 | ||||
| ``` | ||||
| $ go get github.com/mitchellh/mapstructure | ||||
| ``` | ||||
| 
 | ||||
| ## Usage & Example | ||||
| 
 | ||||
| For usage and examples see the [Godoc](http://godoc.org/github.com/mitchellh/mapstructure). | ||||
| 
 | ||||
| The `Decode` function has examples associated with it there. | ||||
| 
 | ||||
| ## But Why?! | ||||
| 
 | ||||
| Go offers fantastic standard libraries for decoding formats such as JSON. | ||||
| The standard method is to have a struct pre-created, and populate that struct | ||||
| from the bytes of the encoded format. This is great, but the problem is if | ||||
| you have configuration or an encoding that changes slightly depending on | ||||
| specific fields. For example, consider this JSON: | ||||
| 
 | ||||
| ```json | ||||
| { | ||||
|   "type": "person", | ||||
|   "name": "Mitchell" | ||||
| } | ||||
| ``` | ||||
| 
 | ||||
| Perhaps we can't populate a specific structure without first reading | ||||
| the "type" field from the JSON. We could always do two passes over the | ||||
| decoding of the JSON (reading the "type" first, and the rest later). | ||||
| However, it is much simpler to just decode this into a `map[string]interface{}` | ||||
| structure, read the "type" key, then use something like this library | ||||
| to decode it into the proper structure. | ||||
							
								
								
									
										256
									
								
								vendor/github.com/mitchellh/mapstructure/decode_hooks.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										256
									
								
								vendor/github.com/mitchellh/mapstructure/decode_hooks.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,256 @@ | |||
| package mapstructure | ||||
| 
 | ||||
| import ( | ||||
| 	"encoding" | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"net" | ||||
| 	"reflect" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| 	"time" | ||||
| ) | ||||
| 
 | ||||
| // typedDecodeHook takes a raw DecodeHookFunc (an interface{}) and turns | ||||
| // it into the proper DecodeHookFunc type, such as DecodeHookFuncType. | ||||
| func typedDecodeHook(h DecodeHookFunc) DecodeHookFunc { | ||||
| 	// Create variables here so we can reference them with the reflect pkg | ||||
| 	var f1 DecodeHookFuncType | ||||
| 	var f2 DecodeHookFuncKind | ||||
| 	var f3 DecodeHookFuncValue | ||||
| 
 | ||||
| 	// Fill in the variables into this interface and the rest is done | ||||
| 	// automatically using the reflect package. | ||||
| 	potential := []interface{}{f1, f2, f3} | ||||
| 
 | ||||
| 	v := reflect.ValueOf(h) | ||||
| 	vt := v.Type() | ||||
| 	for _, raw := range potential { | ||||
| 		pt := reflect.ValueOf(raw).Type() | ||||
| 		if vt.ConvertibleTo(pt) { | ||||
| 			return v.Convert(pt).Interface() | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
| 
 | ||||
| // DecodeHookExec executes the given decode hook. This should be used | ||||
| // since it'll naturally degrade to the older backwards compatible DecodeHookFunc | ||||
| // that took reflect.Kind instead of reflect.Type. | ||||
| func DecodeHookExec( | ||||
| 	raw DecodeHookFunc, | ||||
| 	from reflect.Value, to reflect.Value) (interface{}, error) { | ||||
| 
 | ||||
| 	switch f := typedDecodeHook(raw).(type) { | ||||
| 	case DecodeHookFuncType: | ||||
| 		return f(from.Type(), to.Type(), from.Interface()) | ||||
| 	case DecodeHookFuncKind: | ||||
| 		return f(from.Kind(), to.Kind(), from.Interface()) | ||||
| 	case DecodeHookFuncValue: | ||||
| 		return f(from, to) | ||||
| 	default: | ||||
| 		return nil, errors.New("invalid decode hook signature") | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // ComposeDecodeHookFunc creates a single DecodeHookFunc that | ||||
| // automatically composes multiple DecodeHookFuncs. | ||||
| // | ||||
| // The composed funcs are called in order, with the result of the | ||||
| // previous transformation. | ||||
| func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc { | ||||
| 	return func(f reflect.Value, t reflect.Value) (interface{}, error) { | ||||
| 		var err error | ||||
| 		var data interface{} | ||||
| 		newFrom := f | ||||
| 		for _, f1 := range fs { | ||||
| 			data, err = DecodeHookExec(f1, newFrom, t) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 			newFrom = reflect.ValueOf(data) | ||||
| 		} | ||||
| 
 | ||||
| 		return data, nil | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // StringToSliceHookFunc returns a DecodeHookFunc that converts | ||||
| // string to []string by splitting on the given sep. | ||||
| func StringToSliceHookFunc(sep string) DecodeHookFunc { | ||||
| 	return func( | ||||
| 		f reflect.Kind, | ||||
| 		t reflect.Kind, | ||||
| 		data interface{}) (interface{}, error) { | ||||
| 		if f != reflect.String || t != reflect.Slice { | ||||
| 			return data, nil | ||||
| 		} | ||||
| 
 | ||||
| 		raw := data.(string) | ||||
| 		if raw == "" { | ||||
| 			return []string{}, nil | ||||
| 		} | ||||
| 
 | ||||
| 		return strings.Split(raw, sep), nil | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // StringToTimeDurationHookFunc returns a DecodeHookFunc that converts | ||||
| // strings to time.Duration. | ||||
| func StringToTimeDurationHookFunc() DecodeHookFunc { | ||||
| 	return func( | ||||
| 		f reflect.Type, | ||||
| 		t reflect.Type, | ||||
| 		data interface{}) (interface{}, error) { | ||||
| 		if f.Kind() != reflect.String { | ||||
| 			return data, nil | ||||
| 		} | ||||
| 		if t != reflect.TypeOf(time.Duration(5)) { | ||||
| 			return data, nil | ||||
| 		} | ||||
| 
 | ||||
| 		// Convert it by parsing | ||||
| 		return time.ParseDuration(data.(string)) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // StringToIPHookFunc returns a DecodeHookFunc that converts | ||||
| // strings to net.IP | ||||
| func StringToIPHookFunc() DecodeHookFunc { | ||||
| 	return func( | ||||
| 		f reflect.Type, | ||||
| 		t reflect.Type, | ||||
| 		data interface{}) (interface{}, error) { | ||||
| 		if f.Kind() != reflect.String { | ||||
| 			return data, nil | ||||
| 		} | ||||
| 		if t != reflect.TypeOf(net.IP{}) { | ||||
| 			return data, nil | ||||
| 		} | ||||
| 
 | ||||
| 		// Convert it by parsing | ||||
| 		ip := net.ParseIP(data.(string)) | ||||
| 		if ip == nil { | ||||
| 			return net.IP{}, fmt.Errorf("failed parsing ip %v", data) | ||||
| 		} | ||||
| 
 | ||||
| 		return ip, nil | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // StringToIPNetHookFunc returns a DecodeHookFunc that converts | ||||
| // strings to net.IPNet | ||||
| func StringToIPNetHookFunc() DecodeHookFunc { | ||||
| 	return func( | ||||
| 		f reflect.Type, | ||||
| 		t reflect.Type, | ||||
| 		data interface{}) (interface{}, error) { | ||||
| 		if f.Kind() != reflect.String { | ||||
| 			return data, nil | ||||
| 		} | ||||
| 		if t != reflect.TypeOf(net.IPNet{}) { | ||||
| 			return data, nil | ||||
| 		} | ||||
| 
 | ||||
| 		// Convert it by parsing | ||||
| 		_, net, err := net.ParseCIDR(data.(string)) | ||||
| 		return net, err | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // StringToTimeHookFunc returns a DecodeHookFunc that converts | ||||
| // strings to time.Time. | ||||
| func StringToTimeHookFunc(layout string) DecodeHookFunc { | ||||
| 	return func( | ||||
| 		f reflect.Type, | ||||
| 		t reflect.Type, | ||||
| 		data interface{}) (interface{}, error) { | ||||
| 		if f.Kind() != reflect.String { | ||||
| 			return data, nil | ||||
| 		} | ||||
| 		if t != reflect.TypeOf(time.Time{}) { | ||||
| 			return data, nil | ||||
| 		} | ||||
| 
 | ||||
| 		// Convert it by parsing | ||||
| 		return time.Parse(layout, data.(string)) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // WeaklyTypedHook is a DecodeHookFunc which adds support for weak typing to | ||||
| // the decoder. | ||||
| // | ||||
| // Note that this is significantly different from the WeaklyTypedInput option | ||||
| // of the DecoderConfig. | ||||
| func WeaklyTypedHook( | ||||
| 	f reflect.Kind, | ||||
| 	t reflect.Kind, | ||||
| 	data interface{}) (interface{}, error) { | ||||
| 	dataVal := reflect.ValueOf(data) | ||||
| 	switch t { | ||||
| 	case reflect.String: | ||||
| 		switch f { | ||||
| 		case reflect.Bool: | ||||
| 			if dataVal.Bool() { | ||||
| 				return "1", nil | ||||
| 			} | ||||
| 			return "0", nil | ||||
| 		case reflect.Float32: | ||||
| 			return strconv.FormatFloat(dataVal.Float(), 'f', -1, 64), nil | ||||
| 		case reflect.Int: | ||||
| 			return strconv.FormatInt(dataVal.Int(), 10), nil | ||||
| 		case reflect.Slice: | ||||
| 			dataType := dataVal.Type() | ||||
| 			elemKind := dataType.Elem().Kind() | ||||
| 			if elemKind == reflect.Uint8 { | ||||
| 				return string(dataVal.Interface().([]uint8)), nil | ||||
| 			} | ||||
| 		case reflect.Uint: | ||||
| 			return strconv.FormatUint(dataVal.Uint(), 10), nil | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return data, nil | ||||
| } | ||||
| 
 | ||||
| func RecursiveStructToMapHookFunc() DecodeHookFunc { | ||||
| 	return func(f reflect.Value, t reflect.Value) (interface{}, error) { | ||||
| 		if f.Kind() != reflect.Struct { | ||||
| 			return f.Interface(), nil | ||||
| 		} | ||||
| 
 | ||||
| 		var i interface{} = struct{}{} | ||||
| 		if t.Type() != reflect.TypeOf(&i).Elem() { | ||||
| 			return f.Interface(), nil | ||||
| 		} | ||||
| 
 | ||||
| 		m := make(map[string]interface{}) | ||||
| 		t.Set(reflect.ValueOf(m)) | ||||
| 
 | ||||
| 		return f.Interface(), nil | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // TextUnmarshallerHookFunc returns a DecodeHookFunc that applies | ||||
| // strings to the UnmarshalText function, when the target type | ||||
| // implements the encoding.TextUnmarshaler interface | ||||
| func TextUnmarshallerHookFunc() DecodeHookFuncType { | ||||
| 	return func( | ||||
| 		f reflect.Type, | ||||
| 		t reflect.Type, | ||||
| 		data interface{}) (interface{}, error) { | ||||
| 		if f.Kind() != reflect.String { | ||||
| 			return data, nil | ||||
| 		} | ||||
| 		result := reflect.New(t).Interface() | ||||
| 		unmarshaller, ok := result.(encoding.TextUnmarshaler) | ||||
| 		if !ok { | ||||
| 			return data, nil | ||||
| 		} | ||||
| 		if err := unmarshaller.UnmarshalText([]byte(data.(string))); err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 		return result, nil | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										50
									
								
								vendor/github.com/mitchellh/mapstructure/error.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								vendor/github.com/mitchellh/mapstructure/error.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,50 @@ | |||
| package mapstructure | ||||
| 
 | ||||
| import ( | ||||
| 	"errors" | ||||
| 	"fmt" | ||||
| 	"sort" | ||||
| 	"strings" | ||||
| ) | ||||
| 
 | ||||
| // Error implements the error interface and can represents multiple | ||||
| // errors that occur in the course of a single decode. | ||||
| type Error struct { | ||||
| 	Errors []string | ||||
| } | ||||
| 
 | ||||
| func (e *Error) Error() string { | ||||
| 	points := make([]string, len(e.Errors)) | ||||
| 	for i, err := range e.Errors { | ||||
| 		points[i] = fmt.Sprintf("* %s", err) | ||||
| 	} | ||||
| 
 | ||||
| 	sort.Strings(points) | ||||
| 	return fmt.Sprintf( | ||||
| 		"%d error(s) decoding:\n\n%s", | ||||
| 		len(e.Errors), strings.Join(points, "\n")) | ||||
| } | ||||
| 
 | ||||
| // WrappedErrors implements the errwrap.Wrapper interface to make this | ||||
| // return value more useful with the errwrap and go-multierror libraries. | ||||
| func (e *Error) WrappedErrors() []error { | ||||
| 	if e == nil { | ||||
| 		return nil | ||||
| 	} | ||||
| 
 | ||||
| 	result := make([]error, len(e.Errors)) | ||||
| 	for i, e := range e.Errors { | ||||
| 		result[i] = errors.New(e) | ||||
| 	} | ||||
| 
 | ||||
| 	return result | ||||
| } | ||||
| 
 | ||||
| func appendErrors(errors []string, err error) []string { | ||||
| 	switch e := err.(type) { | ||||
| 	case *Error: | ||||
| 		return append(errors, e.Errors...) | ||||
| 	default: | ||||
| 		return append(errors, e.Error()) | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										3
									
								
								vendor/github.com/mitchellh/mapstructure/go.mod
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								vendor/github.com/mitchellh/mapstructure/go.mod
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| module github.com/mitchellh/mapstructure | ||||
| 
 | ||||
| go 1.14 | ||||
							
								
								
									
										1462
									
								
								vendor/github.com/mitchellh/mapstructure/mapstructure.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1462
									
								
								vendor/github.com/mitchellh/mapstructure/mapstructure.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue