mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-31 16:02:26 -05:00 
			
		
		
		
	[bugfix] Fix Swagger spec and add test script (#2698)
* Add Swagger spec test script * Fix Swagger spec errors not related to statuses with polls * Add API tests that post a status with a poll * Fix creating a status with a poll from form params * Fix Swagger spec errors related to statuses with polls (this is the last error) * Fix Swagger spec warnings not related to unused definitions * Suppress a duplicate list update params definition that was somehow causing wrong param names * Add Swagger test to CI - updates Drone config - vendorizes go-swagger - fixes a file extension issue that caused the test script to generate JSON instead of YAML with the vendorized version * Put `Sample: ` on its own line everywhere * Remove unused id param from emojiCategoriesGet * Add 5 more pairs of profile fields to account update API Swagger * Remove Swagger prefix from dummy fields It makes the generated code look weird * Manually annotate params for statusCreate operation * Fix all remaining Swagger spec warnings - Change some models into operation parameters - Ignore models that already correspond to manually documented operation parameters but can't be trivially changed (those with file fields) * Documented that creating a status with scheduled_at isn't implemented yet * sign drone.yml * Fix filter API Swagger errors * fixup! Fix filter API Swagger errors --------- Co-authored-by: tobi <tobi.smethurst@protonmail.com>
This commit is contained in:
		
					parent
					
						
							
								68c8fe67cc
							
						
					
				
			
			
				commit
				
					
						fc3741365c
					
				
			
		
					 672 changed files with 135624 additions and 713 deletions
				
			
		
							
								
								
									
										26
									
								
								vendor/github.com/go-openapi/swag/.editorconfig
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								vendor/github.com/go-openapi/swag/.editorconfig
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,26 @@ | |||
| # top-most EditorConfig file | ||||
| root = true | ||||
| 
 | ||||
| # Unix-style newlines with a newline ending every file | ||||
| [*] | ||||
| end_of_line = lf | ||||
| insert_final_newline = true | ||||
| indent_style = space | ||||
| indent_size = 2 | ||||
| trim_trailing_whitespace = true | ||||
| 
 | ||||
| # Set default charset | ||||
| [*.{js,py,go,scala,rb,java,html,css,less,sass,md}] | ||||
| charset = utf-8 | ||||
| 
 | ||||
| # Tab indentation (no size specified) | ||||
| [*.go] | ||||
| indent_style = tab | ||||
| 
 | ||||
| [*.md] | ||||
| trim_trailing_whitespace = false | ||||
| 
 | ||||
| # Matches the exact files either package.json or .travis.yml | ||||
| [{package.json,.travis.yml}] | ||||
| indent_style = space | ||||
| indent_size = 2 | ||||
							
								
								
									
										2
									
								
								vendor/github.com/go-openapi/swag/.gitattributes
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								vendor/github.com/go-openapi/swag/.gitattributes
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | |||
| # gofmt always uses LF, whereas Git uses CRLF on Windows. | ||||
| *.go text eol=lf | ||||
							
								
								
									
										4
									
								
								vendor/github.com/go-openapi/swag/.gitignore
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								vendor/github.com/go-openapi/swag/.gitignore
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | |||
| secrets.yml | ||||
| vendor | ||||
| Godeps | ||||
| .idea | ||||
							
								
								
									
										54
									
								
								vendor/github.com/go-openapi/swag/.golangci.yml
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								vendor/github.com/go-openapi/swag/.golangci.yml
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,54 @@ | |||
| linters-settings: | ||||
|   govet: | ||||
|     check-shadowing: true | ||||
|   golint: | ||||
|     min-confidence: 0 | ||||
|   gocyclo: | ||||
|     min-complexity: 25 | ||||
|   maligned: | ||||
|     suggest-new: true | ||||
|   dupl: | ||||
|     threshold: 100 | ||||
|   goconst: | ||||
|     min-len: 3 | ||||
|     min-occurrences: 2 | ||||
| 
 | ||||
| linters: | ||||
|   enable-all: true | ||||
|   disable: | ||||
|     - maligned | ||||
|     - lll | ||||
|     - gochecknoinits | ||||
|     - gochecknoglobals | ||||
|     - nlreturn | ||||
|     - testpackage | ||||
|     - wrapcheck | ||||
|     - gomnd | ||||
|     - exhaustive | ||||
|     - exhaustivestruct | ||||
|     - goerr113 | ||||
|     - wsl | ||||
|     - whitespace | ||||
|     - gofumpt | ||||
|     - godot | ||||
|     - nestif | ||||
|     - godox | ||||
|     - funlen | ||||
|     - gci | ||||
|     - gocognit | ||||
|     - paralleltest | ||||
|     - thelper | ||||
|     - ifshort | ||||
|     - gomoddirectives | ||||
|     - cyclop | ||||
|     - forcetypeassert | ||||
|     - ireturn | ||||
|     - tagliatelle | ||||
|     - varnamelen | ||||
|     - goimports | ||||
|     - tenv | ||||
|     - golint | ||||
|     - exhaustruct | ||||
|     - nilnil | ||||
|     - nonamedreturns | ||||
|     - nosnakecase | ||||
							
								
								
									
										74
									
								
								vendor/github.com/go-openapi/swag/CODE_OF_CONDUCT.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								vendor/github.com/go-openapi/swag/CODE_OF_CONDUCT.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,74 @@ | |||
| # Contributor Covenant Code of Conduct | ||||
| 
 | ||||
| ## Our Pledge | ||||
| 
 | ||||
| In the interest of fostering an open and welcoming environment, we as | ||||
| contributors and maintainers pledge to making participation in our project and | ||||
| our community a harassment-free experience for everyone, regardless of age, body | ||||
| size, disability, ethnicity, gender identity and expression, level of experience, | ||||
| nationality, personal appearance, race, religion, or sexual identity and | ||||
| orientation. | ||||
| 
 | ||||
| ## Our Standards | ||||
| 
 | ||||
| Examples of behavior that contributes to creating a positive environment | ||||
| include: | ||||
| 
 | ||||
| * Using welcoming and inclusive language | ||||
| * Being respectful of differing viewpoints and experiences | ||||
| * Gracefully accepting constructive criticism | ||||
| * Focusing on what is best for the community | ||||
| * Showing empathy towards other community members | ||||
| 
 | ||||
| Examples of unacceptable behavior by participants include: | ||||
| 
 | ||||
| * The use of sexualized language or imagery and unwelcome sexual attention or | ||||
| advances | ||||
| * Trolling, insulting/derogatory comments, and personal or political attacks | ||||
| * Public or private harassment | ||||
| * Publishing others' private information, such as a physical or electronic | ||||
|   address, without explicit permission | ||||
| * Other conduct which could reasonably be considered inappropriate in a | ||||
|   professional setting | ||||
| 
 | ||||
| ## Our Responsibilities | ||||
| 
 | ||||
| Project maintainers are responsible for clarifying the standards of acceptable | ||||
| behavior and are expected to take appropriate and fair corrective action in | ||||
| response to any instances of unacceptable behavior. | ||||
| 
 | ||||
| Project maintainers have the right and responsibility to remove, edit, or | ||||
| reject comments, commits, code, wiki edits, issues, and other contributions | ||||
| that are not aligned to this Code of Conduct, or to ban temporarily or | ||||
| permanently any contributor for other behaviors that they deem inappropriate, | ||||
| threatening, offensive, or harmful. | ||||
| 
 | ||||
| ## Scope | ||||
| 
 | ||||
| This Code of Conduct applies both within project spaces and in public spaces | ||||
| when an individual is representing the project or its community. Examples of | ||||
| representing a project or community include using an official project e-mail | ||||
| address, posting via an official social media account, or acting as an appointed | ||||
| representative at an online or offline event. Representation of a project may be | ||||
| further defined and clarified by project maintainers. | ||||
| 
 | ||||
| ## Enforcement | ||||
| 
 | ||||
| Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||||
| reported by contacting the project team at ivan+abuse@flanders.co.nz. All | ||||
| complaints will be reviewed and investigated and will result in a response that | ||||
| is deemed necessary and appropriate to the circumstances. The project team is | ||||
| obligated to maintain confidentiality with regard to the reporter of an incident. | ||||
| Further details of specific enforcement policies may be posted separately. | ||||
| 
 | ||||
| Project maintainers who do not follow or enforce the Code of Conduct in good | ||||
| faith may face temporary or permanent repercussions as determined by other | ||||
| members of the project's leadership. | ||||
| 
 | ||||
| ## Attribution | ||||
| 
 | ||||
| This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||||
| available at [http://contributor-covenant.org/version/1/4][version] | ||||
| 
 | ||||
| [homepage]: http://contributor-covenant.org | ||||
| [version]: http://contributor-covenant.org/version/1/4/ | ||||
							
								
								
									
										202
									
								
								vendor/github.com/go-openapi/swag/LICENSE
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										202
									
								
								vendor/github.com/go-openapi/swag/LICENSE
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,202 @@ | |||
| 
 | ||||
|                                  Apache License | ||||
|                            Version 2.0, January 2004 | ||||
|                         http://www.apache.org/licenses/ | ||||
| 
 | ||||
|    TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | ||||
| 
 | ||||
|    1. Definitions. | ||||
| 
 | ||||
|       "License" shall mean the terms and conditions for use, reproduction, | ||||
|       and distribution as defined by Sections 1 through 9 of this document. | ||||
| 
 | ||||
|       "Licensor" shall mean the copyright owner or entity authorized by | ||||
|       the copyright owner that is granting the License. | ||||
| 
 | ||||
|       "Legal Entity" shall mean the union of the acting entity and all | ||||
|       other entities that control, are controlled by, or are under common | ||||
|       control with that entity. For the purposes of this definition, | ||||
|       "control" means (i) the power, direct or indirect, to cause the | ||||
|       direction or management of such entity, whether by contract or | ||||
|       otherwise, or (ii) ownership of fifty percent (50%) or more of the | ||||
|       outstanding shares, or (iii) beneficial ownership of such entity. | ||||
| 
 | ||||
|       "You" (or "Your") shall mean an individual or Legal Entity | ||||
|       exercising permissions granted by this License. | ||||
| 
 | ||||
|       "Source" form shall mean the preferred form for making modifications, | ||||
|       including but not limited to software source code, documentation | ||||
|       source, and configuration files. | ||||
| 
 | ||||
|       "Object" form shall mean any form resulting from mechanical | ||||
|       transformation or translation of a Source form, including but | ||||
|       not limited to compiled object code, generated documentation, | ||||
|       and conversions to other media types. | ||||
| 
 | ||||
|       "Work" shall mean the work of authorship, whether in Source or | ||||
|       Object form, made available under the License, as indicated by a | ||||
|       copyright notice that is included in or attached to the work | ||||
|       (an example is provided in the Appendix below). | ||||
| 
 | ||||
|       "Derivative Works" shall mean any work, whether in Source or Object | ||||
|       form, that is based on (or derived from) the Work and for which the | ||||
|       editorial revisions, annotations, elaborations, or other modifications | ||||
|       represent, as a whole, an original work of authorship. For the purposes | ||||
|       of this License, Derivative Works shall not include works that remain | ||||
|       separable from, or merely link (or bind by name) to the interfaces of, | ||||
|       the Work and Derivative Works thereof. | ||||
| 
 | ||||
|       "Contribution" shall mean any work of authorship, including | ||||
|       the original version of the Work and any modifications or additions | ||||
|       to that Work or Derivative Works thereof, that is intentionally | ||||
|       submitted to Licensor for inclusion in the Work by the copyright owner | ||||
|       or by an individual or Legal Entity authorized to submit on behalf of | ||||
|       the copyright owner. For the purposes of this definition, "submitted" | ||||
|       means any form of electronic, verbal, or written communication sent | ||||
|       to the Licensor or its representatives, including but not limited to | ||||
|       communication on electronic mailing lists, source code control systems, | ||||
|       and issue tracking systems that are managed by, or on behalf of, the | ||||
|       Licensor for the purpose of discussing and improving the Work, but | ||||
|       excluding communication that is conspicuously marked or otherwise | ||||
|       designated in writing by the copyright owner as "Not a Contribution." | ||||
| 
 | ||||
|       "Contributor" shall mean Licensor and any individual or Legal Entity | ||||
|       on behalf of whom a Contribution has been received by Licensor and | ||||
|       subsequently incorporated within the Work. | ||||
| 
 | ||||
|    2. Grant of Copyright License. Subject to the terms and conditions of | ||||
|       this License, each Contributor hereby grants to You a perpetual, | ||||
|       worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||||
|       copyright license to reproduce, prepare Derivative Works of, | ||||
|       publicly display, publicly perform, sublicense, and distribute the | ||||
|       Work and such Derivative Works in Source or Object form. | ||||
| 
 | ||||
|    3. Grant of Patent License. Subject to the terms and conditions of | ||||
|       this License, each Contributor hereby grants to You a perpetual, | ||||
|       worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||||
|       (except as stated in this section) patent license to make, have made, | ||||
|       use, offer to sell, sell, import, and otherwise transfer the Work, | ||||
|       where such license applies only to those patent claims licensable | ||||
|       by such Contributor that are necessarily infringed by their | ||||
|       Contribution(s) alone or by combination of their Contribution(s) | ||||
|       with the Work to which such Contribution(s) was submitted. If You | ||||
|       institute patent litigation against any entity (including a | ||||
|       cross-claim or counterclaim in a lawsuit) alleging that the Work | ||||
|       or a Contribution incorporated within the Work constitutes direct | ||||
|       or contributory patent infringement, then any patent licenses | ||||
|       granted to You under this License for that Work shall terminate | ||||
|       as of the date such litigation is filed. | ||||
| 
 | ||||
|    4. Redistribution. You may reproduce and distribute copies of the | ||||
|       Work or Derivative Works thereof in any medium, with or without | ||||
|       modifications, and in Source or Object form, provided that You | ||||
|       meet the following conditions: | ||||
| 
 | ||||
|       (a) You must give any other recipients of the Work or | ||||
|           Derivative Works a copy of this License; and | ||||
| 
 | ||||
|       (b) You must cause any modified files to carry prominent notices | ||||
|           stating that You changed the files; and | ||||
| 
 | ||||
|       (c) You must retain, in the Source form of any Derivative Works | ||||
|           that You distribute, all copyright, patent, trademark, and | ||||
|           attribution notices from the Source form of the Work, | ||||
|           excluding those notices that do not pertain to any part of | ||||
|           the Derivative Works; and | ||||
| 
 | ||||
|       (d) If the Work includes a "NOTICE" text file as part of its | ||||
|           distribution, then any Derivative Works that You distribute must | ||||
|           include a readable copy of the attribution notices contained | ||||
|           within such NOTICE file, excluding those notices that do not | ||||
|           pertain to any part of the Derivative Works, in at least one | ||||
|           of the following places: within a NOTICE text file distributed | ||||
|           as part of the Derivative Works; within the Source form or | ||||
|           documentation, if provided along with the Derivative Works; or, | ||||
|           within a display generated by the Derivative Works, if and | ||||
|           wherever such third-party notices normally appear. The contents | ||||
|           of the NOTICE file are for informational purposes only and | ||||
|           do not modify the License. You may add Your own attribution | ||||
|           notices within Derivative Works that You distribute, alongside | ||||
|           or as an addendum to the NOTICE text from the Work, provided | ||||
|           that such additional attribution notices cannot be construed | ||||
|           as modifying the License. | ||||
| 
 | ||||
|       You may add Your own copyright statement to Your modifications and | ||||
|       may provide additional or different license terms and conditions | ||||
|       for use, reproduction, or distribution of Your modifications, or | ||||
|       for any such Derivative Works as a whole, provided Your use, | ||||
|       reproduction, and distribution of the Work otherwise complies with | ||||
|       the conditions stated in this License. | ||||
| 
 | ||||
|    5. Submission of Contributions. Unless You explicitly state otherwise, | ||||
|       any Contribution intentionally submitted for inclusion in the Work | ||||
|       by You to the Licensor shall be under the terms and conditions of | ||||
|       this License, without any additional terms or conditions. | ||||
|       Notwithstanding the above, nothing herein shall supersede or modify | ||||
|       the terms of any separate license agreement you may have executed | ||||
|       with Licensor regarding such Contributions. | ||||
| 
 | ||||
|    6. Trademarks. This License does not grant permission to use the trade | ||||
|       names, trademarks, service marks, or product names of the Licensor, | ||||
|       except as required for reasonable and customary use in describing the | ||||
|       origin of the Work and reproducing the content of the NOTICE file. | ||||
| 
 | ||||
|    7. Disclaimer of Warranty. Unless required by applicable law or | ||||
|       agreed to in writing, Licensor provides the Work (and each | ||||
|       Contributor provides its Contributions) on an "AS IS" BASIS, | ||||
|       WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||||
|       implied, including, without limitation, any warranties or conditions | ||||
|       of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A | ||||
|       PARTICULAR PURPOSE. You are solely responsible for determining the | ||||
|       appropriateness of using or redistributing the Work and assume any | ||||
|       risks associated with Your exercise of permissions under this License. | ||||
| 
 | ||||
|    8. Limitation of Liability. In no event and under no legal theory, | ||||
|       whether in tort (including negligence), contract, or otherwise, | ||||
|       unless required by applicable law (such as deliberate and grossly | ||||
|       negligent acts) or agreed to in writing, shall any Contributor be | ||||
|       liable to You for damages, including any direct, indirect, special, | ||||
|       incidental, or consequential damages of any character arising as a | ||||
|       result of this License or out of the use or inability to use the | ||||
|       Work (including but not limited to damages for loss of goodwill, | ||||
|       work stoppage, computer failure or malfunction, or any and all | ||||
|       other commercial damages or losses), even if such Contributor | ||||
|       has been advised of the possibility of such damages. | ||||
| 
 | ||||
|    9. Accepting Warranty or Additional Liability. While redistributing | ||||
|       the Work or Derivative Works thereof, You may choose to offer, | ||||
|       and charge a fee for, acceptance of support, warranty, indemnity, | ||||
|       or other liability obligations and/or rights consistent with this | ||||
|       License. However, in accepting such obligations, You may act only | ||||
|       on Your own behalf and on Your sole responsibility, not on behalf | ||||
|       of any other Contributor, and only if You agree to indemnify, | ||||
|       defend, and hold each Contributor harmless for any liability | ||||
|       incurred by, or claims asserted against, such Contributor by reason | ||||
|       of your accepting any such warranty or additional liability. | ||||
| 
 | ||||
|    END OF TERMS AND CONDITIONS | ||||
| 
 | ||||
|    APPENDIX: How to apply the Apache License to your work. | ||||
| 
 | ||||
|       To apply the Apache License to your work, attach the following | ||||
|       boilerplate notice, with the fields enclosed by brackets "[]" | ||||
|       replaced with your own identifying information. (Don't include | ||||
|       the brackets!)  The text should be enclosed in the appropriate | ||||
|       comment syntax for the file format. We also recommend that a | ||||
|       file or class name and description of purpose be included on the | ||||
|       same "printed page" as the copyright notice for easier | ||||
|       identification within third-party archives. | ||||
| 
 | ||||
|    Copyright [yyyy] [name of copyright owner] | ||||
| 
 | ||||
|    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. | ||||
							
								
								
									
										21
									
								
								vendor/github.com/go-openapi/swag/README.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								vendor/github.com/go-openapi/swag/README.md
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,21 @@ | |||
| # Swag [](https://travis-ci.org/go-openapi/swag) [](https://codecov.io/gh/go-openapi/swag) [](https://slackin.goswagger.io) | ||||
| 
 | ||||
| [](https://raw.githubusercontent.com/go-openapi/swag/master/LICENSE) | ||||
| [](http://godoc.org/github.com/go-openapi/swag) | ||||
| [](https://goreportcard.com/report/github.com/go-openapi/swag) | ||||
| 
 | ||||
| Contains a bunch of helper functions for go-openapi and go-swagger projects. | ||||
| 
 | ||||
| You may also use it standalone for your projects. | ||||
| 
 | ||||
| * convert between value and pointers for builtin types | ||||
| * convert from string to builtin types (wraps strconv) | ||||
| * fast json concatenation | ||||
| * search in path | ||||
| * load from file or http | ||||
| * name mangling | ||||
| 
 | ||||
| 
 | ||||
| This repo has only few dependencies outside of the standard library: | ||||
| 
 | ||||
| * YAML utilities depend on gopkg.in/yaml.v2 | ||||
							
								
								
									
										208
									
								
								vendor/github.com/go-openapi/swag/convert.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										208
									
								
								vendor/github.com/go-openapi/swag/convert.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,208 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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 swag | ||||
| 
 | ||||
| import ( | ||||
| 	"math" | ||||
| 	"strconv" | ||||
| 	"strings" | ||||
| ) | ||||
| 
 | ||||
| // same as ECMA Number.MAX_SAFE_INTEGER and Number.MIN_SAFE_INTEGER | ||||
| const ( | ||||
| 	maxJSONFloat         = float64(1<<53 - 1)  // 9007199254740991.0 	 	 2^53 - 1 | ||||
| 	minJSONFloat         = -float64(1<<53 - 1) //-9007199254740991.0	-2^53 - 1 | ||||
| 	epsilon      float64 = 1e-9 | ||||
| ) | ||||
| 
 | ||||
| // IsFloat64AJSONInteger allow for integers [-2^53, 2^53-1] inclusive | ||||
| func IsFloat64AJSONInteger(f float64) bool { | ||||
| 	if math.IsNaN(f) || math.IsInf(f, 0) || f < minJSONFloat || f > maxJSONFloat { | ||||
| 		return false | ||||
| 	} | ||||
| 	fa := math.Abs(f) | ||||
| 	g := float64(uint64(f)) | ||||
| 	ga := math.Abs(g) | ||||
| 
 | ||||
| 	diff := math.Abs(f - g) | ||||
| 
 | ||||
| 	// more info: https://floating-point-gui.de/errors/comparison/#look-out-for-edge-cases | ||||
| 	switch { | ||||
| 	case f == g: // best case | ||||
| 		return true | ||||
| 	case f == float64(int64(f)) || f == float64(uint64(f)): // optimistic case | ||||
| 		return true | ||||
| 	case f == 0 || g == 0 || diff < math.SmallestNonzeroFloat64: // very close to 0 values | ||||
| 		return diff < (epsilon * math.SmallestNonzeroFloat64) | ||||
| 	} | ||||
| 	// check the relative error | ||||
| 	return diff/math.Min(fa+ga, math.MaxFloat64) < epsilon | ||||
| } | ||||
| 
 | ||||
| var evaluatesAsTrue map[string]struct{} | ||||
| 
 | ||||
| func init() { | ||||
| 	evaluatesAsTrue = map[string]struct{}{ | ||||
| 		"true":     {}, | ||||
| 		"1":        {}, | ||||
| 		"yes":      {}, | ||||
| 		"ok":       {}, | ||||
| 		"y":        {}, | ||||
| 		"on":       {}, | ||||
| 		"selected": {}, | ||||
| 		"checked":  {}, | ||||
| 		"t":        {}, | ||||
| 		"enabled":  {}, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // ConvertBool turn a string into a boolean | ||||
| func ConvertBool(str string) (bool, error) { | ||||
| 	_, ok := evaluatesAsTrue[strings.ToLower(str)] | ||||
| 	return ok, nil | ||||
| } | ||||
| 
 | ||||
| // ConvertFloat32 turn a string into a float32 | ||||
| func ConvertFloat32(str string) (float32, error) { | ||||
| 	f, err := strconv.ParseFloat(str, 32) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
| 	return float32(f), nil | ||||
| } | ||||
| 
 | ||||
| // ConvertFloat64 turn a string into a float64 | ||||
| func ConvertFloat64(str string) (float64, error) { | ||||
| 	return strconv.ParseFloat(str, 64) | ||||
| } | ||||
| 
 | ||||
| // ConvertInt8 turn a string into an int8 | ||||
| func ConvertInt8(str string) (int8, error) { | ||||
| 	i, err := strconv.ParseInt(str, 10, 8) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
| 	return int8(i), nil | ||||
| } | ||||
| 
 | ||||
| // ConvertInt16 turn a string into an int16 | ||||
| func ConvertInt16(str string) (int16, error) { | ||||
| 	i, err := strconv.ParseInt(str, 10, 16) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
| 	return int16(i), nil | ||||
| } | ||||
| 
 | ||||
| // ConvertInt32 turn a string into an int32 | ||||
| func ConvertInt32(str string) (int32, error) { | ||||
| 	i, err := strconv.ParseInt(str, 10, 32) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
| 	return int32(i), nil | ||||
| } | ||||
| 
 | ||||
| // ConvertInt64 turn a string into an int64 | ||||
| func ConvertInt64(str string) (int64, error) { | ||||
| 	return strconv.ParseInt(str, 10, 64) | ||||
| } | ||||
| 
 | ||||
| // ConvertUint8 turn a string into an uint8 | ||||
| func ConvertUint8(str string) (uint8, error) { | ||||
| 	i, err := strconv.ParseUint(str, 10, 8) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
| 	return uint8(i), nil | ||||
| } | ||||
| 
 | ||||
| // ConvertUint16 turn a string into an uint16 | ||||
| func ConvertUint16(str string) (uint16, error) { | ||||
| 	i, err := strconv.ParseUint(str, 10, 16) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
| 	return uint16(i), nil | ||||
| } | ||||
| 
 | ||||
| // ConvertUint32 turn a string into an uint32 | ||||
| func ConvertUint32(str string) (uint32, error) { | ||||
| 	i, err := strconv.ParseUint(str, 10, 32) | ||||
| 	if err != nil { | ||||
| 		return 0, err | ||||
| 	} | ||||
| 	return uint32(i), nil | ||||
| } | ||||
| 
 | ||||
| // ConvertUint64 turn a string into an uint64 | ||||
| func ConvertUint64(str string) (uint64, error) { | ||||
| 	return strconv.ParseUint(str, 10, 64) | ||||
| } | ||||
| 
 | ||||
| // FormatBool turns a boolean into a string | ||||
| func FormatBool(value bool) string { | ||||
| 	return strconv.FormatBool(value) | ||||
| } | ||||
| 
 | ||||
| // FormatFloat32 turns a float32 into a string | ||||
| func FormatFloat32(value float32) string { | ||||
| 	return strconv.FormatFloat(float64(value), 'f', -1, 32) | ||||
| } | ||||
| 
 | ||||
| // FormatFloat64 turns a float64 into a string | ||||
| func FormatFloat64(value float64) string { | ||||
| 	return strconv.FormatFloat(value, 'f', -1, 64) | ||||
| } | ||||
| 
 | ||||
| // FormatInt8 turns an int8 into a string | ||||
| func FormatInt8(value int8) string { | ||||
| 	return strconv.FormatInt(int64(value), 10) | ||||
| } | ||||
| 
 | ||||
| // FormatInt16 turns an int16 into a string | ||||
| func FormatInt16(value int16) string { | ||||
| 	return strconv.FormatInt(int64(value), 10) | ||||
| } | ||||
| 
 | ||||
| // FormatInt32 turns an int32 into a string | ||||
| func FormatInt32(value int32) string { | ||||
| 	return strconv.Itoa(int(value)) | ||||
| } | ||||
| 
 | ||||
| // FormatInt64 turns an int64 into a string | ||||
| func FormatInt64(value int64) string { | ||||
| 	return strconv.FormatInt(value, 10) | ||||
| } | ||||
| 
 | ||||
| // FormatUint8 turns an uint8 into a string | ||||
| func FormatUint8(value uint8) string { | ||||
| 	return strconv.FormatUint(uint64(value), 10) | ||||
| } | ||||
| 
 | ||||
| // FormatUint16 turns an uint16 into a string | ||||
| func FormatUint16(value uint16) string { | ||||
| 	return strconv.FormatUint(uint64(value), 10) | ||||
| } | ||||
| 
 | ||||
| // FormatUint32 turns an uint32 into a string | ||||
| func FormatUint32(value uint32) string { | ||||
| 	return strconv.FormatUint(uint64(value), 10) | ||||
| } | ||||
| 
 | ||||
| // FormatUint64 turns an uint64 into a string | ||||
| func FormatUint64(value uint64) string { | ||||
| 	return strconv.FormatUint(value, 10) | ||||
| } | ||||
							
								
								
									
										730
									
								
								vendor/github.com/go-openapi/swag/convert_types.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										730
									
								
								vendor/github.com/go-openapi/swag/convert_types.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,730 @@ | |||
| package swag | ||||
| 
 | ||||
| import "time" | ||||
| 
 | ||||
| // This file was taken from the aws go sdk | ||||
| 
 | ||||
| // String returns a pointer to of the string value passed in. | ||||
| func String(v string) *string { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // StringValue returns the value of the string pointer passed in or | ||||
| // "" if the pointer is nil. | ||||
| func StringValue(v *string) string { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
| 
 | ||||
| // StringSlice converts a slice of string values into a slice of | ||||
| // string pointers | ||||
| func StringSlice(src []string) []*string { | ||||
| 	dst := make([]*string, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // StringValueSlice converts a slice of string pointers into a slice of | ||||
| // string values | ||||
| func StringValueSlice(src []*string) []string { | ||||
| 	dst := make([]string, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // StringMap converts a string map of string values into a string | ||||
| // map of string pointers | ||||
| func StringMap(src map[string]string) map[string]*string { | ||||
| 	dst := make(map[string]*string) | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // StringValueMap converts a string map of string pointers into a string | ||||
| // map of string values | ||||
| func StringValueMap(src map[string]*string) map[string]string { | ||||
| 	dst := make(map[string]string) | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Bool returns a pointer to of the bool value passed in. | ||||
| func Bool(v bool) *bool { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // BoolValue returns the value of the bool pointer passed in or | ||||
| // false if the pointer is nil. | ||||
| func BoolValue(v *bool) bool { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
| 
 | ||||
| // BoolSlice converts a slice of bool values into a slice of | ||||
| // bool pointers | ||||
| func BoolSlice(src []bool) []*bool { | ||||
| 	dst := make([]*bool, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // BoolValueSlice converts a slice of bool pointers into a slice of | ||||
| // bool values | ||||
| func BoolValueSlice(src []*bool) []bool { | ||||
| 	dst := make([]bool, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // BoolMap converts a string map of bool values into a string | ||||
| // map of bool pointers | ||||
| func BoolMap(src map[string]bool) map[string]*bool { | ||||
| 	dst := make(map[string]*bool) | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // BoolValueMap converts a string map of bool pointers into a string | ||||
| // map of bool values | ||||
| func BoolValueMap(src map[string]*bool) map[string]bool { | ||||
| 	dst := make(map[string]bool) | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Int returns a pointer to of the int value passed in. | ||||
| func Int(v int) *int { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // IntValue returns the value of the int pointer passed in or | ||||
| // 0 if the pointer is nil. | ||||
| func IntValue(v *int) int { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| // IntSlice converts a slice of int values into a slice of | ||||
| // int pointers | ||||
| func IntSlice(src []int) []*int { | ||||
| 	dst := make([]*int, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // IntValueSlice converts a slice of int pointers into a slice of | ||||
| // int values | ||||
| func IntValueSlice(src []*int) []int { | ||||
| 	dst := make([]int, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // IntMap converts a string map of int values into a string | ||||
| // map of int pointers | ||||
| func IntMap(src map[string]int) map[string]*int { | ||||
| 	dst := make(map[string]*int) | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // IntValueMap converts a string map of int pointers into a string | ||||
| // map of int values | ||||
| func IntValueMap(src map[string]*int) map[string]int { | ||||
| 	dst := make(map[string]int) | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Int32 returns a pointer to of the int32 value passed in. | ||||
| func Int32(v int32) *int32 { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // Int32Value returns the value of the int32 pointer passed in or | ||||
| // 0 if the pointer is nil. | ||||
| func Int32Value(v *int32) int32 { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| // Int32Slice converts a slice of int32 values into a slice of | ||||
| // int32 pointers | ||||
| func Int32Slice(src []int32) []*int32 { | ||||
| 	dst := make([]*int32, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Int32ValueSlice converts a slice of int32 pointers into a slice of | ||||
| // int32 values | ||||
| func Int32ValueSlice(src []*int32) []int32 { | ||||
| 	dst := make([]int32, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Int32Map converts a string map of int32 values into a string | ||||
| // map of int32 pointers | ||||
| func Int32Map(src map[string]int32) map[string]*int32 { | ||||
| 	dst := make(map[string]*int32) | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Int32ValueMap converts a string map of int32 pointers into a string | ||||
| // map of int32 values | ||||
| func Int32ValueMap(src map[string]*int32) map[string]int32 { | ||||
| 	dst := make(map[string]int32) | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Int64 returns a pointer to of the int64 value passed in. | ||||
| func Int64(v int64) *int64 { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // Int64Value returns the value of the int64 pointer passed in or | ||||
| // 0 if the pointer is nil. | ||||
| func Int64Value(v *int64) int64 { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| // Int64Slice converts a slice of int64 values into a slice of | ||||
| // int64 pointers | ||||
| func Int64Slice(src []int64) []*int64 { | ||||
| 	dst := make([]*int64, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Int64ValueSlice converts a slice of int64 pointers into a slice of | ||||
| // int64 values | ||||
| func Int64ValueSlice(src []*int64) []int64 { | ||||
| 	dst := make([]int64, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Int64Map converts a string map of int64 values into a string | ||||
| // map of int64 pointers | ||||
| func Int64Map(src map[string]int64) map[string]*int64 { | ||||
| 	dst := make(map[string]*int64) | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Int64ValueMap converts a string map of int64 pointers into a string | ||||
| // map of int64 values | ||||
| func Int64ValueMap(src map[string]*int64) map[string]int64 { | ||||
| 	dst := make(map[string]int64) | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint16 returns a pointer to of the uint16 value passed in. | ||||
| func Uint16(v uint16) *uint16 { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // Uint16Value returns the value of the uint16 pointer passed in or | ||||
| // 0 if the pointer is nil. | ||||
| func Uint16Value(v *uint16) uint16 { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 
 | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| // Uint16Slice converts a slice of uint16 values into a slice of | ||||
| // uint16 pointers | ||||
| func Uint16Slice(src []uint16) []*uint16 { | ||||
| 	dst := make([]*uint16, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 
 | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint16ValueSlice converts a slice of uint16 pointers into a slice of | ||||
| // uint16 values | ||||
| func Uint16ValueSlice(src []*uint16) []uint16 { | ||||
| 	dst := make([]uint16, len(src)) | ||||
| 
 | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint16Map converts a string map of uint16 values into a string | ||||
| // map of uint16 pointers | ||||
| func Uint16Map(src map[string]uint16) map[string]*uint16 { | ||||
| 	dst := make(map[string]*uint16) | ||||
| 
 | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 
 | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint16ValueMap converts a string map of uint16 pointers into a string | ||||
| // map of uint16 values | ||||
| func Uint16ValueMap(src map[string]*uint16) map[string]uint16 { | ||||
| 	dst := make(map[string]uint16) | ||||
| 
 | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint returns a pointer to of the uint value passed in. | ||||
| func Uint(v uint) *uint { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // UintValue returns the value of the uint pointer passed in or | ||||
| // 0 if the pointer is nil. | ||||
| func UintValue(v *uint) uint { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| // UintSlice converts a slice of uint values into a slice of | ||||
| // uint pointers | ||||
| func UintSlice(src []uint) []*uint { | ||||
| 	dst := make([]*uint, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // UintValueSlice converts a slice of uint pointers into a slice of | ||||
| // uint values | ||||
| func UintValueSlice(src []*uint) []uint { | ||||
| 	dst := make([]uint, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // UintMap converts a string map of uint values into a string | ||||
| // map of uint pointers | ||||
| func UintMap(src map[string]uint) map[string]*uint { | ||||
| 	dst := make(map[string]*uint) | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // UintValueMap converts a string map of uint pointers into a string | ||||
| // map of uint values | ||||
| func UintValueMap(src map[string]*uint) map[string]uint { | ||||
| 	dst := make(map[string]uint) | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint32 returns a pointer to of the uint32 value passed in. | ||||
| func Uint32(v uint32) *uint32 { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // Uint32Value returns the value of the uint32 pointer passed in or | ||||
| // 0 if the pointer is nil. | ||||
| func Uint32Value(v *uint32) uint32 { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| // Uint32Slice converts a slice of uint32 values into a slice of | ||||
| // uint32 pointers | ||||
| func Uint32Slice(src []uint32) []*uint32 { | ||||
| 	dst := make([]*uint32, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint32ValueSlice converts a slice of uint32 pointers into a slice of | ||||
| // uint32 values | ||||
| func Uint32ValueSlice(src []*uint32) []uint32 { | ||||
| 	dst := make([]uint32, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint32Map converts a string map of uint32 values into a string | ||||
| // map of uint32 pointers | ||||
| func Uint32Map(src map[string]uint32) map[string]*uint32 { | ||||
| 	dst := make(map[string]*uint32) | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint32ValueMap converts a string map of uint32 pointers into a string | ||||
| // map of uint32 values | ||||
| func Uint32ValueMap(src map[string]*uint32) map[string]uint32 { | ||||
| 	dst := make(map[string]uint32) | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint64 returns a pointer to of the uint64 value passed in. | ||||
| func Uint64(v uint64) *uint64 { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // Uint64Value returns the value of the uint64 pointer passed in or | ||||
| // 0 if the pointer is nil. | ||||
| func Uint64Value(v *uint64) uint64 { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| // Uint64Slice converts a slice of uint64 values into a slice of | ||||
| // uint64 pointers | ||||
| func Uint64Slice(src []uint64) []*uint64 { | ||||
| 	dst := make([]*uint64, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint64ValueSlice converts a slice of uint64 pointers into a slice of | ||||
| // uint64 values | ||||
| func Uint64ValueSlice(src []*uint64) []uint64 { | ||||
| 	dst := make([]uint64, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint64Map converts a string map of uint64 values into a string | ||||
| // map of uint64 pointers | ||||
| func Uint64Map(src map[string]uint64) map[string]*uint64 { | ||||
| 	dst := make(map[string]*uint64) | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Uint64ValueMap converts a string map of uint64 pointers into a string | ||||
| // map of uint64 values | ||||
| func Uint64ValueMap(src map[string]*uint64) map[string]uint64 { | ||||
| 	dst := make(map[string]uint64) | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Float32 returns a pointer to of the float32 value passed in. | ||||
| func Float32(v float32) *float32 { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // Float32Value returns the value of the float32 pointer passed in or | ||||
| // 0 if the pointer is nil. | ||||
| func Float32Value(v *float32) float32 { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 
 | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| // Float32Slice converts a slice of float32 values into a slice of | ||||
| // float32 pointers | ||||
| func Float32Slice(src []float32) []*float32 { | ||||
| 	dst := make([]*float32, len(src)) | ||||
| 
 | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 
 | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Float32ValueSlice converts a slice of float32 pointers into a slice of | ||||
| // float32 values | ||||
| func Float32ValueSlice(src []*float32) []float32 { | ||||
| 	dst := make([]float32, len(src)) | ||||
| 
 | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Float32Map converts a string map of float32 values into a string | ||||
| // map of float32 pointers | ||||
| func Float32Map(src map[string]float32) map[string]*float32 { | ||||
| 	dst := make(map[string]*float32) | ||||
| 
 | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 
 | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Float32ValueMap converts a string map of float32 pointers into a string | ||||
| // map of float32 values | ||||
| func Float32ValueMap(src map[string]*float32) map[string]float32 { | ||||
| 	dst := make(map[string]float32) | ||||
| 
 | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Float64 returns a pointer to of the float64 value passed in. | ||||
| func Float64(v float64) *float64 { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // Float64Value returns the value of the float64 pointer passed in or | ||||
| // 0 if the pointer is nil. | ||||
| func Float64Value(v *float64) float64 { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 	return 0 | ||||
| } | ||||
| 
 | ||||
| // Float64Slice converts a slice of float64 values into a slice of | ||||
| // float64 pointers | ||||
| func Float64Slice(src []float64) []*float64 { | ||||
| 	dst := make([]*float64, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Float64ValueSlice converts a slice of float64 pointers into a slice of | ||||
| // float64 values | ||||
| func Float64ValueSlice(src []*float64) []float64 { | ||||
| 	dst := make([]float64, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Float64Map converts a string map of float64 values into a string | ||||
| // map of float64 pointers | ||||
| func Float64Map(src map[string]float64) map[string]*float64 { | ||||
| 	dst := make(map[string]*float64) | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Float64ValueMap converts a string map of float64 pointers into a string | ||||
| // map of float64 values | ||||
| func Float64ValueMap(src map[string]*float64) map[string]float64 { | ||||
| 	dst := make(map[string]float64) | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // Time returns a pointer to of the time.Time value passed in. | ||||
| func Time(v time.Time) *time.Time { | ||||
| 	return &v | ||||
| } | ||||
| 
 | ||||
| // TimeValue returns the value of the time.Time pointer passed in or | ||||
| // time.Time{} if the pointer is nil. | ||||
| func TimeValue(v *time.Time) time.Time { | ||||
| 	if v != nil { | ||||
| 		return *v | ||||
| 	} | ||||
| 	return time.Time{} | ||||
| } | ||||
| 
 | ||||
| // TimeSlice converts a slice of time.Time values into a slice of | ||||
| // time.Time pointers | ||||
| func TimeSlice(src []time.Time) []*time.Time { | ||||
| 	dst := make([]*time.Time, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		dst[i] = &(src[i]) | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // TimeValueSlice converts a slice of time.Time pointers into a slice of | ||||
| // time.Time values | ||||
| func TimeValueSlice(src []*time.Time) []time.Time { | ||||
| 	dst := make([]time.Time, len(src)) | ||||
| 	for i := 0; i < len(src); i++ { | ||||
| 		if src[i] != nil { | ||||
| 			dst[i] = *(src[i]) | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // TimeMap converts a string map of time.Time values into a string | ||||
| // map of time.Time pointers | ||||
| func TimeMap(src map[string]time.Time) map[string]*time.Time { | ||||
| 	dst := make(map[string]*time.Time) | ||||
| 	for k, val := range src { | ||||
| 		v := val | ||||
| 		dst[k] = &v | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
| 
 | ||||
| // TimeValueMap converts a string map of time.Time pointers into a string | ||||
| // map of time.Time values | ||||
| func TimeValueMap(src map[string]*time.Time) map[string]time.Time { | ||||
| 	dst := make(map[string]time.Time) | ||||
| 	for k, val := range src { | ||||
| 		if val != nil { | ||||
| 			dst[k] = *val | ||||
| 		} | ||||
| 	} | ||||
| 	return dst | ||||
| } | ||||
							
								
								
									
										31
									
								
								vendor/github.com/go-openapi/swag/doc.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								vendor/github.com/go-openapi/swag/doc.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,31 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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 swag contains a bunch of helper functions for go-openapi and go-swagger projects. | ||||
| 
 | ||||
| You may also use it standalone for your projects. | ||||
| 
 | ||||
|   - convert between value and pointers for builtin types | ||||
|   - convert from string to builtin types (wraps strconv) | ||||
|   - fast json concatenation | ||||
|   - search in path | ||||
|   - load from file or http | ||||
|   - name mangling | ||||
| 
 | ||||
| This repo has only few dependencies outside of the standard library: | ||||
| 
 | ||||
|   - YAML utilities depend on gopkg.in/yaml.v2 | ||||
| */ | ||||
| package swag | ||||
							
								
								
									
										33
									
								
								vendor/github.com/go-openapi/swag/file.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								vendor/github.com/go-openapi/swag/file.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,33 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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 swag | ||||
| 
 | ||||
| import "mime/multipart" | ||||
| 
 | ||||
| // File represents an uploaded file. | ||||
| type File struct { | ||||
| 	Data   multipart.File | ||||
| 	Header *multipart.FileHeader | ||||
| } | ||||
| 
 | ||||
| // Read bytes from the file | ||||
| func (f *File) Read(p []byte) (n int, err error) { | ||||
| 	return f.Data.Read(p) | ||||
| } | ||||
| 
 | ||||
| // Close the file | ||||
| func (f *File) Close() error { | ||||
| 	return f.Data.Close() | ||||
| } | ||||
							
								
								
									
										312
									
								
								vendor/github.com/go-openapi/swag/json.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										312
									
								
								vendor/github.com/go-openapi/swag/json.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,312 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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 swag | ||||
| 
 | ||||
| import ( | ||||
| 	"bytes" | ||||
| 	"encoding/json" | ||||
| 	"log" | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
| 	"sync" | ||||
| 
 | ||||
| 	"github.com/mailru/easyjson/jlexer" | ||||
| 	"github.com/mailru/easyjson/jwriter" | ||||
| ) | ||||
| 
 | ||||
| // nullJSON represents a JSON object with null type | ||||
| var nullJSON = []byte("null") | ||||
| 
 | ||||
| // DefaultJSONNameProvider the default cache for types | ||||
| var DefaultJSONNameProvider = NewNameProvider() | ||||
| 
 | ||||
| const comma = byte(',') | ||||
| 
 | ||||
| var closers map[byte]byte | ||||
| 
 | ||||
| func init() { | ||||
| 	closers = map[byte]byte{ | ||||
| 		'{': '}', | ||||
| 		'[': ']', | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| type ejMarshaler interface { | ||||
| 	MarshalEasyJSON(w *jwriter.Writer) | ||||
| } | ||||
| 
 | ||||
| type ejUnmarshaler interface { | ||||
| 	UnmarshalEasyJSON(w *jlexer.Lexer) | ||||
| } | ||||
| 
 | ||||
| // WriteJSON writes json data, prefers finding an appropriate interface to short-circuit the marshaler | ||||
| // so it takes the fastest option available. | ||||
| func WriteJSON(data interface{}) ([]byte, error) { | ||||
| 	if d, ok := data.(ejMarshaler); ok { | ||||
| 		jw := new(jwriter.Writer) | ||||
| 		d.MarshalEasyJSON(jw) | ||||
| 		return jw.BuildBytes() | ||||
| 	} | ||||
| 	if d, ok := data.(json.Marshaler); ok { | ||||
| 		return d.MarshalJSON() | ||||
| 	} | ||||
| 	return json.Marshal(data) | ||||
| } | ||||
| 
 | ||||
| // ReadJSON reads json data, prefers finding an appropriate interface to short-circuit the unmarshaler | ||||
| // so it takes the fastest option available | ||||
| func ReadJSON(data []byte, value interface{}) error { | ||||
| 	trimmedData := bytes.Trim(data, "\x00") | ||||
| 	if d, ok := value.(ejUnmarshaler); ok { | ||||
| 		jl := &jlexer.Lexer{Data: trimmedData} | ||||
| 		d.UnmarshalEasyJSON(jl) | ||||
| 		return jl.Error() | ||||
| 	} | ||||
| 	if d, ok := value.(json.Unmarshaler); ok { | ||||
| 		return d.UnmarshalJSON(trimmedData) | ||||
| 	} | ||||
| 	return json.Unmarshal(trimmedData, value) | ||||
| } | ||||
| 
 | ||||
| // DynamicJSONToStruct converts an untyped json structure into a struct | ||||
| func DynamicJSONToStruct(data interface{}, target interface{}) error { | ||||
| 	// TODO: convert straight to a json typed map  (mergo + iterate?) | ||||
| 	b, err := WriteJSON(data) | ||||
| 	if err != nil { | ||||
| 		return err | ||||
| 	} | ||||
| 	return ReadJSON(b, target) | ||||
| } | ||||
| 
 | ||||
| // ConcatJSON concatenates multiple json objects efficiently | ||||
| func ConcatJSON(blobs ...[]byte) []byte { | ||||
| 	if len(blobs) == 0 { | ||||
| 		return nil | ||||
| 	} | ||||
| 
 | ||||
| 	last := len(blobs) - 1 | ||||
| 	for blobs[last] == nil || bytes.Equal(blobs[last], nullJSON) { | ||||
| 		// strips trailing null objects | ||||
| 		last-- | ||||
| 		if last < 0 { | ||||
| 			// there was nothing but "null"s or nil... | ||||
| 			return nil | ||||
| 		} | ||||
| 	} | ||||
| 	if last == 0 { | ||||
| 		return blobs[0] | ||||
| 	} | ||||
| 
 | ||||
| 	var opening, closing byte | ||||
| 	var idx, a int | ||||
| 	buf := bytes.NewBuffer(nil) | ||||
| 
 | ||||
| 	for i, b := range blobs[:last+1] { | ||||
| 		if b == nil || bytes.Equal(b, nullJSON) { | ||||
| 			// a null object is in the list: skip it | ||||
| 			continue | ||||
| 		} | ||||
| 		if len(b) > 0 && opening == 0 { // is this an array or an object? | ||||
| 			opening, closing = b[0], closers[b[0]] | ||||
| 		} | ||||
| 
 | ||||
| 		if opening != '{' && opening != '[' { | ||||
| 			continue // don't know how to concatenate non container objects | ||||
| 		} | ||||
| 
 | ||||
| 		if len(b) < 3 { // yep empty but also the last one, so closing this thing | ||||
| 			if i == last && a > 0 { | ||||
| 				if err := buf.WriteByte(closing); err != nil { | ||||
| 					log.Println(err) | ||||
| 				} | ||||
| 			} | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
| 		idx = 0 | ||||
| 		if a > 0 { // we need to join with a comma for everything beyond the first non-empty item | ||||
| 			if err := buf.WriteByte(comma); err != nil { | ||||
| 				log.Println(err) | ||||
| 			} | ||||
| 			idx = 1 // this is not the first or the last so we want to drop the leading bracket | ||||
| 		} | ||||
| 
 | ||||
| 		if i != last { // not the last one, strip brackets | ||||
| 			if _, err := buf.Write(b[idx : len(b)-1]); err != nil { | ||||
| 				log.Println(err) | ||||
| 			} | ||||
| 		} else { // last one, strip only the leading bracket | ||||
| 			if _, err := buf.Write(b[idx:]); err != nil { | ||||
| 				log.Println(err) | ||||
| 			} | ||||
| 		} | ||||
| 		a++ | ||||
| 	} | ||||
| 	// somehow it ended up being empty, so provide a default value | ||||
| 	if buf.Len() == 0 { | ||||
| 		if err := buf.WriteByte(opening); err != nil { | ||||
| 			log.Println(err) | ||||
| 		} | ||||
| 		if err := buf.WriteByte(closing); err != nil { | ||||
| 			log.Println(err) | ||||
| 		} | ||||
| 	} | ||||
| 	return buf.Bytes() | ||||
| } | ||||
| 
 | ||||
| // ToDynamicJSON turns an object into a properly JSON typed structure | ||||
| func ToDynamicJSON(data interface{}) interface{} { | ||||
| 	// TODO: convert straight to a json typed map (mergo + iterate?) | ||||
| 	b, err := json.Marshal(data) | ||||
| 	if err != nil { | ||||
| 		log.Println(err) | ||||
| 	} | ||||
| 	var res interface{} | ||||
| 	if err := json.Unmarshal(b, &res); err != nil { | ||||
| 		log.Println(err) | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| // FromDynamicJSON turns an object into a properly JSON typed structure | ||||
| func FromDynamicJSON(data, target interface{}) error { | ||||
| 	b, err := json.Marshal(data) | ||||
| 	if err != nil { | ||||
| 		log.Println(err) | ||||
| 	} | ||||
| 	return json.Unmarshal(b, target) | ||||
| } | ||||
| 
 | ||||
| // NameProvider represents an object capable of translating from go property names | ||||
| // to json property names | ||||
| // This type is thread-safe. | ||||
| type NameProvider struct { | ||||
| 	lock  *sync.Mutex | ||||
| 	index map[reflect.Type]nameIndex | ||||
| } | ||||
| 
 | ||||
| type nameIndex struct { | ||||
| 	jsonNames map[string]string | ||||
| 	goNames   map[string]string | ||||
| } | ||||
| 
 | ||||
| // NewNameProvider creates a new name provider | ||||
| func NewNameProvider() *NameProvider { | ||||
| 	return &NameProvider{ | ||||
| 		lock:  &sync.Mutex{}, | ||||
| 		index: make(map[reflect.Type]nameIndex), | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func buildnameIndex(tpe reflect.Type, idx, reverseIdx map[string]string) { | ||||
| 	for i := 0; i < tpe.NumField(); i++ { | ||||
| 		targetDes := tpe.Field(i) | ||||
| 
 | ||||
| 		if targetDes.PkgPath != "" { // unexported | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
| 		if targetDes.Anonymous { // walk embedded structures tree down first | ||||
| 			buildnameIndex(targetDes.Type, idx, reverseIdx) | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
| 		if tag := targetDes.Tag.Get("json"); tag != "" { | ||||
| 
 | ||||
| 			parts := strings.Split(tag, ",") | ||||
| 			if len(parts) == 0 { | ||||
| 				continue | ||||
| 			} | ||||
| 
 | ||||
| 			nm := parts[0] | ||||
| 			if nm == "-" { | ||||
| 				continue | ||||
| 			} | ||||
| 			if nm == "" { // empty string means we want to use the Go name | ||||
| 				nm = targetDes.Name | ||||
| 			} | ||||
| 
 | ||||
| 			idx[nm] = targetDes.Name | ||||
| 			reverseIdx[targetDes.Name] = nm | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func newNameIndex(tpe reflect.Type) nameIndex { | ||||
| 	var idx = make(map[string]string, tpe.NumField()) | ||||
| 	var reverseIdx = make(map[string]string, tpe.NumField()) | ||||
| 
 | ||||
| 	buildnameIndex(tpe, idx, reverseIdx) | ||||
| 	return nameIndex{jsonNames: idx, goNames: reverseIdx} | ||||
| } | ||||
| 
 | ||||
| // GetJSONNames gets all the json property names for a type | ||||
| func (n *NameProvider) GetJSONNames(subject interface{}) []string { | ||||
| 	n.lock.Lock() | ||||
| 	defer n.lock.Unlock() | ||||
| 	tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() | ||||
| 	names, ok := n.index[tpe] | ||||
| 	if !ok { | ||||
| 		names = n.makeNameIndex(tpe) | ||||
| 	} | ||||
| 
 | ||||
| 	res := make([]string, 0, len(names.jsonNames)) | ||||
| 	for k := range names.jsonNames { | ||||
| 		res = append(res, k) | ||||
| 	} | ||||
| 	return res | ||||
| } | ||||
| 
 | ||||
| // GetJSONName gets the json name for a go property name | ||||
| func (n *NameProvider) GetJSONName(subject interface{}, name string) (string, bool) { | ||||
| 	tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() | ||||
| 	return n.GetJSONNameForType(tpe, name) | ||||
| } | ||||
| 
 | ||||
| // GetJSONNameForType gets the json name for a go property name on a given type | ||||
| func (n *NameProvider) GetJSONNameForType(tpe reflect.Type, name string) (string, bool) { | ||||
| 	n.lock.Lock() | ||||
| 	defer n.lock.Unlock() | ||||
| 	names, ok := n.index[tpe] | ||||
| 	if !ok { | ||||
| 		names = n.makeNameIndex(tpe) | ||||
| 	} | ||||
| 	nme, ok := names.goNames[name] | ||||
| 	return nme, ok | ||||
| } | ||||
| 
 | ||||
| func (n *NameProvider) makeNameIndex(tpe reflect.Type) nameIndex { | ||||
| 	names := newNameIndex(tpe) | ||||
| 	n.index[tpe] = names | ||||
| 	return names | ||||
| } | ||||
| 
 | ||||
| // GetGoName gets the go name for a json property name | ||||
| func (n *NameProvider) GetGoName(subject interface{}, name string) (string, bool) { | ||||
| 	tpe := reflect.Indirect(reflect.ValueOf(subject)).Type() | ||||
| 	return n.GetGoNameForType(tpe, name) | ||||
| } | ||||
| 
 | ||||
| // GetGoNameForType gets the go name for a given type for a json property name | ||||
| func (n *NameProvider) GetGoNameForType(tpe reflect.Type, name string) (string, bool) { | ||||
| 	n.lock.Lock() | ||||
| 	defer n.lock.Unlock() | ||||
| 	names, ok := n.index[tpe] | ||||
| 	if !ok { | ||||
| 		names = n.makeNameIndex(tpe) | ||||
| 	} | ||||
| 	nme, ok := names.jsonNames[name] | ||||
| 	return nme, ok | ||||
| } | ||||
							
								
								
									
										121
									
								
								vendor/github.com/go-openapi/swag/loading.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								vendor/github.com/go-openapi/swag/loading.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,121 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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 swag | ||||
| 
 | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"io" | ||||
| 	"log" | ||||
| 	"net/http" | ||||
| 	"net/url" | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"runtime" | ||||
| 	"strings" | ||||
| 	"time" | ||||
| ) | ||||
| 
 | ||||
| // LoadHTTPTimeout the default timeout for load requests | ||||
| var LoadHTTPTimeout = 30 * time.Second | ||||
| 
 | ||||
| // LoadHTTPBasicAuthUsername the username to use when load requests require basic auth | ||||
| var LoadHTTPBasicAuthUsername = "" | ||||
| 
 | ||||
| // LoadHTTPBasicAuthPassword the password to use when load requests require basic auth | ||||
| var LoadHTTPBasicAuthPassword = "" | ||||
| 
 | ||||
| // LoadHTTPCustomHeaders an optional collection of custom HTTP headers for load requests | ||||
| var LoadHTTPCustomHeaders = map[string]string{} | ||||
| 
 | ||||
| // LoadFromFileOrHTTP loads the bytes from a file or a remote http server based on the path passed in | ||||
| func LoadFromFileOrHTTP(path string) ([]byte, error) { | ||||
| 	return LoadStrategy(path, os.ReadFile, loadHTTPBytes(LoadHTTPTimeout))(path) | ||||
| } | ||||
| 
 | ||||
| // LoadFromFileOrHTTPWithTimeout loads the bytes from a file or a remote http server based on the path passed in | ||||
| // timeout arg allows for per request overriding of the request timeout | ||||
| func LoadFromFileOrHTTPWithTimeout(path string, timeout time.Duration) ([]byte, error) { | ||||
| 	return LoadStrategy(path, os.ReadFile, loadHTTPBytes(timeout))(path) | ||||
| } | ||||
| 
 | ||||
| // LoadStrategy returns a loader function for a given path or uri | ||||
| func LoadStrategy(path string, local, remote func(string) ([]byte, error)) func(string) ([]byte, error) { | ||||
| 	if strings.HasPrefix(path, "http") { | ||||
| 		return remote | ||||
| 	} | ||||
| 	return func(pth string) ([]byte, error) { | ||||
| 		upth, err := pathUnescape(pth) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 
 | ||||
| 		if strings.HasPrefix(pth, `file://`) { | ||||
| 			if runtime.GOOS == "windows" { | ||||
| 				// support for canonical file URIs on windows. | ||||
| 				// Zero tolerance here for dodgy URIs. | ||||
| 				u, _ := url.Parse(upth) | ||||
| 				if u.Host != "" { | ||||
| 					// assume UNC name (volume share) | ||||
| 					// file://host/share/folder\... ==> \\host\share\path\folder | ||||
| 					// NOTE: UNC port not yet supported | ||||
| 					upth = strings.Join([]string{`\`, u.Host, u.Path}, `\`) | ||||
| 				} else { | ||||
| 					// file:///c:/folder/... ==> just remove the leading slash | ||||
| 					upth = strings.TrimPrefix(upth, `file:///`) | ||||
| 				} | ||||
| 			} else { | ||||
| 				upth = strings.TrimPrefix(upth, `file://`) | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return local(filepath.FromSlash(upth)) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func loadHTTPBytes(timeout time.Duration) func(path string) ([]byte, error) { | ||||
| 	return func(path string) ([]byte, error) { | ||||
| 		client := &http.Client{Timeout: timeout} | ||||
| 		req, err := http.NewRequest(http.MethodGet, path, nil) //nolint:noctx | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 
 | ||||
| 		if LoadHTTPBasicAuthUsername != "" && LoadHTTPBasicAuthPassword != "" { | ||||
| 			req.SetBasicAuth(LoadHTTPBasicAuthUsername, LoadHTTPBasicAuthPassword) | ||||
| 		} | ||||
| 
 | ||||
| 		for key, val := range LoadHTTPCustomHeaders { | ||||
| 			req.Header.Set(key, val) | ||||
| 		} | ||||
| 
 | ||||
| 		resp, err := client.Do(req) | ||||
| 		defer func() { | ||||
| 			if resp != nil { | ||||
| 				if e := resp.Body.Close(); e != nil { | ||||
| 					log.Println(e) | ||||
| 				} | ||||
| 			} | ||||
| 		}() | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 
 | ||||
| 		if resp.StatusCode != http.StatusOK { | ||||
| 			return nil, fmt.Errorf("could not access document at %q [%s] ", path, resp.Status) | ||||
| 		} | ||||
| 
 | ||||
| 		return io.ReadAll(resp.Body) | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										87
									
								
								vendor/github.com/go-openapi/swag/name_lexem.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								vendor/github.com/go-openapi/swag/name_lexem.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,87 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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 swag | ||||
| 
 | ||||
| import "unicode" | ||||
| 
 | ||||
| type ( | ||||
| 	nameLexem interface { | ||||
| 		GetUnsafeGoName() string | ||||
| 		GetOriginal() string | ||||
| 		IsInitialism() bool | ||||
| 	} | ||||
| 
 | ||||
| 	initialismNameLexem struct { | ||||
| 		original          string | ||||
| 		matchedInitialism string | ||||
| 	} | ||||
| 
 | ||||
| 	casualNameLexem struct { | ||||
| 		original string | ||||
| 	} | ||||
| ) | ||||
| 
 | ||||
| func newInitialismNameLexem(original, matchedInitialism string) *initialismNameLexem { | ||||
| 	return &initialismNameLexem{ | ||||
| 		original:          original, | ||||
| 		matchedInitialism: matchedInitialism, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func newCasualNameLexem(original string) *casualNameLexem { | ||||
| 	return &casualNameLexem{ | ||||
| 		original: original, | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (l *initialismNameLexem) GetUnsafeGoName() string { | ||||
| 	return l.matchedInitialism | ||||
| } | ||||
| 
 | ||||
| func (l *casualNameLexem) GetUnsafeGoName() string { | ||||
| 	var first rune | ||||
| 	var rest string | ||||
| 	for i, orig := range l.original { | ||||
| 		if i == 0 { | ||||
| 			first = orig | ||||
| 			continue | ||||
| 		} | ||||
| 		if i > 0 { | ||||
| 			rest = l.original[i:] | ||||
| 			break | ||||
| 		} | ||||
| 	} | ||||
| 	if len(l.original) > 1 { | ||||
| 		return string(unicode.ToUpper(first)) + lower(rest) | ||||
| 	} | ||||
| 
 | ||||
| 	return l.original | ||||
| } | ||||
| 
 | ||||
| func (l *initialismNameLexem) GetOriginal() string { | ||||
| 	return l.original | ||||
| } | ||||
| 
 | ||||
| func (l *casualNameLexem) GetOriginal() string { | ||||
| 	return l.original | ||||
| } | ||||
| 
 | ||||
| func (l *initialismNameLexem) IsInitialism() bool { | ||||
| 	return true | ||||
| } | ||||
| 
 | ||||
| func (l *casualNameLexem) IsInitialism() bool { | ||||
| 	return false | ||||
| } | ||||
							
								
								
									
										38
									
								
								vendor/github.com/go-openapi/swag/net.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								vendor/github.com/go-openapi/swag/net.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,38 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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 swag | ||||
| 
 | ||||
| import ( | ||||
| 	"net" | ||||
| 	"strconv" | ||||
| ) | ||||
| 
 | ||||
| // SplitHostPort splits a network address into a host and a port. | ||||
| // The port is -1 when there is no port to be found | ||||
| func SplitHostPort(addr string) (host string, port int, err error) { | ||||
| 	h, p, err := net.SplitHostPort(addr) | ||||
| 	if err != nil { | ||||
| 		return "", -1, err | ||||
| 	} | ||||
| 	if p == "" { | ||||
| 		return "", -1, &net.AddrError{Err: "missing port in address", Addr: addr} | ||||
| 	} | ||||
| 
 | ||||
| 	pi, err := strconv.Atoi(p) | ||||
| 	if err != nil { | ||||
| 		return "", -1, err | ||||
| 	} | ||||
| 	return h, pi, nil | ||||
| } | ||||
							
								
								
									
										59
									
								
								vendor/github.com/go-openapi/swag/path.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								vendor/github.com/go-openapi/swag/path.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,59 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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 swag | ||||
| 
 | ||||
| import ( | ||||
| 	"os" | ||||
| 	"path/filepath" | ||||
| 	"runtime" | ||||
| 	"strings" | ||||
| ) | ||||
| 
 | ||||
| const ( | ||||
| 	// GOPATHKey represents the env key for gopath | ||||
| 	GOPATHKey = "GOPATH" | ||||
| ) | ||||
| 
 | ||||
| // FindInSearchPath finds a package in a provided lists of paths | ||||
| func FindInSearchPath(searchPath, pkg string) string { | ||||
| 	pathsList := filepath.SplitList(searchPath) | ||||
| 	for _, path := range pathsList { | ||||
| 		if evaluatedPath, err := filepath.EvalSymlinks(filepath.Join(path, "src", pkg)); err == nil { | ||||
| 			if _, err := os.Stat(evaluatedPath); err == nil { | ||||
| 				return evaluatedPath | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return "" | ||||
| } | ||||
| 
 | ||||
| // FindInGoSearchPath finds a package in the $GOPATH:$GOROOT | ||||
| func FindInGoSearchPath(pkg string) string { | ||||
| 	return FindInSearchPath(FullGoSearchPath(), pkg) | ||||
| } | ||||
| 
 | ||||
| // FullGoSearchPath gets the search paths for finding packages | ||||
| func FullGoSearchPath() string { | ||||
| 	allPaths := os.Getenv(GOPATHKey) | ||||
| 	if allPaths == "" { | ||||
| 		allPaths = filepath.Join(os.Getenv("HOME"), "go") | ||||
| 	} | ||||
| 	if allPaths != "" { | ||||
| 		allPaths = strings.Join([]string{allPaths, runtime.GOROOT()}, ":") | ||||
| 	} else { | ||||
| 		allPaths = runtime.GOROOT() | ||||
| 	} | ||||
| 	return allPaths | ||||
| } | ||||
							
								
								
									
										24
									
								
								vendor/github.com/go-openapi/swag/post_go18.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								vendor/github.com/go-openapi/swag/post_go18.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,24 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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. | ||||
| 
 | ||||
| //go:build go1.8 | ||||
| // +build go1.8 | ||||
| 
 | ||||
| package swag | ||||
| 
 | ||||
| import "net/url" | ||||
| 
 | ||||
| func pathUnescape(path string) (string, error) { | ||||
| 	return url.PathUnescape(path) | ||||
| } | ||||
							
								
								
									
										68
									
								
								vendor/github.com/go-openapi/swag/post_go19.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								vendor/github.com/go-openapi/swag/post_go19.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,68 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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. | ||||
| 
 | ||||
| //go:build go1.9 | ||||
| // +build go1.9 | ||||
| 
 | ||||
| package swag | ||||
| 
 | ||||
| import ( | ||||
| 	"sort" | ||||
| 	"sync" | ||||
| ) | ||||
| 
 | ||||
| // indexOfInitialisms is a thread-safe implementation of the sorted index of initialisms. | ||||
| // Since go1.9, this may be implemented with sync.Map. | ||||
| type indexOfInitialisms struct { | ||||
| 	sortMutex *sync.Mutex | ||||
| 	index     *sync.Map | ||||
| } | ||||
| 
 | ||||
| func newIndexOfInitialisms() *indexOfInitialisms { | ||||
| 	return &indexOfInitialisms{ | ||||
| 		sortMutex: new(sync.Mutex), | ||||
| 		index:     new(sync.Map), | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (m *indexOfInitialisms) load(initial map[string]bool) *indexOfInitialisms { | ||||
| 	m.sortMutex.Lock() | ||||
| 	defer m.sortMutex.Unlock() | ||||
| 	for k, v := range initial { | ||||
| 		m.index.Store(k, v) | ||||
| 	} | ||||
| 	return m | ||||
| } | ||||
| 
 | ||||
| func (m *indexOfInitialisms) isInitialism(key string) bool { | ||||
| 	_, ok := m.index.Load(key) | ||||
| 	return ok | ||||
| } | ||||
| 
 | ||||
| func (m *indexOfInitialisms) add(key string) *indexOfInitialisms { | ||||
| 	m.index.Store(key, true) | ||||
| 	return m | ||||
| } | ||||
| 
 | ||||
| func (m *indexOfInitialisms) sorted() (result []string) { | ||||
| 	m.sortMutex.Lock() | ||||
| 	defer m.sortMutex.Unlock() | ||||
| 	m.index.Range(func(key, value interface{}) bool { | ||||
| 		k := key.(string) | ||||
| 		result = append(result, k) | ||||
| 		return true | ||||
| 	}) | ||||
| 	sort.Sort(sort.Reverse(byInitialism(result))) | ||||
| 	return | ||||
| } | ||||
							
								
								
									
										24
									
								
								vendor/github.com/go-openapi/swag/pre_go18.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								vendor/github.com/go-openapi/swag/pre_go18.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,24 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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. | ||||
| 
 | ||||
| //go:build !go1.8 | ||||
| // +build !go1.8 | ||||
| 
 | ||||
| package swag | ||||
| 
 | ||||
| import "net/url" | ||||
| 
 | ||||
| func pathUnescape(path string) (string, error) { | ||||
| 	return url.QueryUnescape(path) | ||||
| } | ||||
							
								
								
									
										70
									
								
								vendor/github.com/go-openapi/swag/pre_go19.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										70
									
								
								vendor/github.com/go-openapi/swag/pre_go19.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,70 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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. | ||||
| 
 | ||||
| //go:build !go1.9 | ||||
| // +build !go1.9 | ||||
| 
 | ||||
| package swag | ||||
| 
 | ||||
| import ( | ||||
| 	"sort" | ||||
| 	"sync" | ||||
| ) | ||||
| 
 | ||||
| // indexOfInitialisms is a thread-safe implementation of the sorted index of initialisms. | ||||
| // Before go1.9, this may be implemented with a mutex on the map. | ||||
| type indexOfInitialisms struct { | ||||
| 	getMutex *sync.Mutex | ||||
| 	index    map[string]bool | ||||
| } | ||||
| 
 | ||||
| func newIndexOfInitialisms() *indexOfInitialisms { | ||||
| 	return &indexOfInitialisms{ | ||||
| 		getMutex: new(sync.Mutex), | ||||
| 		index:    make(map[string]bool, 50), | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func (m *indexOfInitialisms) load(initial map[string]bool) *indexOfInitialisms { | ||||
| 	m.getMutex.Lock() | ||||
| 	defer m.getMutex.Unlock() | ||||
| 	for k, v := range initial { | ||||
| 		m.index[k] = v | ||||
| 	} | ||||
| 	return m | ||||
| } | ||||
| 
 | ||||
| func (m *indexOfInitialisms) isInitialism(key string) bool { | ||||
| 	m.getMutex.Lock() | ||||
| 	defer m.getMutex.Unlock() | ||||
| 	_, ok := m.index[key] | ||||
| 	return ok | ||||
| } | ||||
| 
 | ||||
| func (m *indexOfInitialisms) add(key string) *indexOfInitialisms { | ||||
| 	m.getMutex.Lock() | ||||
| 	defer m.getMutex.Unlock() | ||||
| 	m.index[key] = true | ||||
| 	return m | ||||
| } | ||||
| 
 | ||||
| func (m *indexOfInitialisms) sorted() (result []string) { | ||||
| 	m.getMutex.Lock() | ||||
| 	defer m.getMutex.Unlock() | ||||
| 	for k := range m.index { | ||||
| 		result = append(result, k) | ||||
| 	} | ||||
| 	sort.Sort(sort.Reverse(byInitialism(result))) | ||||
| 	return | ||||
| } | ||||
							
								
								
									
										262
									
								
								vendor/github.com/go-openapi/swag/split.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										262
									
								
								vendor/github.com/go-openapi/swag/split.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,262 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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 swag | ||||
| 
 | ||||
| import ( | ||||
| 	"unicode" | ||||
| ) | ||||
| 
 | ||||
| var nameReplaceTable = map[rune]string{ | ||||
| 	'@': "At ", | ||||
| 	'&': "And ", | ||||
| 	'|': "Pipe ", | ||||
| 	'$': "Dollar ", | ||||
| 	'!': "Bang ", | ||||
| 	'-': "", | ||||
| 	'_': "", | ||||
| } | ||||
| 
 | ||||
| type ( | ||||
| 	splitter struct { | ||||
| 		postSplitInitialismCheck bool | ||||
| 		initialisms              []string | ||||
| 	} | ||||
| 
 | ||||
| 	splitterOption func(*splitter) *splitter | ||||
| ) | ||||
| 
 | ||||
| // split calls the splitter; splitter provides more control and post options | ||||
| func split(str string) []string { | ||||
| 	lexems := newSplitter().split(str) | ||||
| 	result := make([]string, 0, len(lexems)) | ||||
| 
 | ||||
| 	for _, lexem := range lexems { | ||||
| 		result = append(result, lexem.GetOriginal()) | ||||
| 	} | ||||
| 
 | ||||
| 	return result | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| func (s *splitter) split(str string) []nameLexem { | ||||
| 	return s.toNameLexems(str) | ||||
| } | ||||
| 
 | ||||
| func newSplitter(options ...splitterOption) *splitter { | ||||
| 	splitter := &splitter{ | ||||
| 		postSplitInitialismCheck: false, | ||||
| 		initialisms:              initialisms, | ||||
| 	} | ||||
| 
 | ||||
| 	for _, option := range options { | ||||
| 		splitter = option(splitter) | ||||
| 	} | ||||
| 
 | ||||
| 	return splitter | ||||
| } | ||||
| 
 | ||||
| // withPostSplitInitialismCheck allows to catch initialisms after main split process | ||||
| func withPostSplitInitialismCheck(s *splitter) *splitter { | ||||
| 	s.postSplitInitialismCheck = true | ||||
| 	return s | ||||
| } | ||||
| 
 | ||||
| type ( | ||||
| 	initialismMatch struct { | ||||
| 		start, end int | ||||
| 		body       []rune | ||||
| 		complete   bool | ||||
| 	} | ||||
| 	initialismMatches []*initialismMatch | ||||
| ) | ||||
| 
 | ||||
| func (s *splitter) toNameLexems(name string) []nameLexem { | ||||
| 	nameRunes := []rune(name) | ||||
| 	matches := s.gatherInitialismMatches(nameRunes) | ||||
| 	return s.mapMatchesToNameLexems(nameRunes, matches) | ||||
| } | ||||
| 
 | ||||
| func (s *splitter) gatherInitialismMatches(nameRunes []rune) initialismMatches { | ||||
| 	matches := make(initialismMatches, 0) | ||||
| 
 | ||||
| 	for currentRunePosition, currentRune := range nameRunes { | ||||
| 		newMatches := make(initialismMatches, 0, len(matches)) | ||||
| 
 | ||||
| 		// check current initialism matches | ||||
| 		for _, match := range matches { | ||||
| 			if keepCompleteMatch := match.complete; keepCompleteMatch { | ||||
| 				newMatches = append(newMatches, match) | ||||
| 				continue | ||||
| 			} | ||||
| 
 | ||||
| 			// drop failed match | ||||
| 			currentMatchRune := match.body[currentRunePosition-match.start] | ||||
| 			if !s.initialismRuneEqual(currentMatchRune, currentRune) { | ||||
| 				continue | ||||
| 			} | ||||
| 
 | ||||
| 			// try to complete ongoing match | ||||
| 			if currentRunePosition-match.start == len(match.body)-1 { | ||||
| 				// we are close; the next step is to check the symbol ahead | ||||
| 				// if it is a small letter, then it is not the end of match | ||||
| 				// but beginning of the next word | ||||
| 
 | ||||
| 				if currentRunePosition < len(nameRunes)-1 { | ||||
| 					nextRune := nameRunes[currentRunePosition+1] | ||||
| 					if newWord := unicode.IsLower(nextRune); newWord { | ||||
| 						// oh ok, it was the start of a new word | ||||
| 						continue | ||||
| 					} | ||||
| 				} | ||||
| 
 | ||||
| 				match.complete = true | ||||
| 				match.end = currentRunePosition | ||||
| 			} | ||||
| 
 | ||||
| 			newMatches = append(newMatches, match) | ||||
| 		} | ||||
| 
 | ||||
| 		// check for new initialism matches | ||||
| 		for _, initialism := range s.initialisms { | ||||
| 			initialismRunes := []rune(initialism) | ||||
| 			if s.initialismRuneEqual(initialismRunes[0], currentRune) { | ||||
| 				newMatches = append(newMatches, &initialismMatch{ | ||||
| 					start:    currentRunePosition, | ||||
| 					body:     initialismRunes, | ||||
| 					complete: false, | ||||
| 				}) | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		matches = newMatches | ||||
| 	} | ||||
| 
 | ||||
| 	return matches | ||||
| } | ||||
| 
 | ||||
| func (s *splitter) mapMatchesToNameLexems(nameRunes []rune, matches initialismMatches) []nameLexem { | ||||
| 	nameLexems := make([]nameLexem, 0) | ||||
| 
 | ||||
| 	var lastAcceptedMatch *initialismMatch | ||||
| 	for _, match := range matches { | ||||
| 		if !match.complete { | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
| 		if firstMatch := lastAcceptedMatch == nil; firstMatch { | ||||
| 			nameLexems = append(nameLexems, s.breakCasualString(nameRunes[:match.start])...) | ||||
| 			nameLexems = append(nameLexems, s.breakInitialism(string(match.body))) | ||||
| 
 | ||||
| 			lastAcceptedMatch = match | ||||
| 
 | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
| 		if overlappedMatch := match.start <= lastAcceptedMatch.end; overlappedMatch { | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
| 		middle := nameRunes[lastAcceptedMatch.end+1 : match.start] | ||||
| 		nameLexems = append(nameLexems, s.breakCasualString(middle)...) | ||||
| 		nameLexems = append(nameLexems, s.breakInitialism(string(match.body))) | ||||
| 
 | ||||
| 		lastAcceptedMatch = match | ||||
| 	} | ||||
| 
 | ||||
| 	// we have not found any accepted matches | ||||
| 	if lastAcceptedMatch == nil { | ||||
| 		return s.breakCasualString(nameRunes) | ||||
| 	} | ||||
| 
 | ||||
| 	if lastAcceptedMatch.end+1 != len(nameRunes) { | ||||
| 		rest := nameRunes[lastAcceptedMatch.end+1:] | ||||
| 		nameLexems = append(nameLexems, s.breakCasualString(rest)...) | ||||
| 	} | ||||
| 
 | ||||
| 	return nameLexems | ||||
| } | ||||
| 
 | ||||
| func (s *splitter) initialismRuneEqual(a, b rune) bool { | ||||
| 	return a == b | ||||
| } | ||||
| 
 | ||||
| func (s *splitter) breakInitialism(original string) nameLexem { | ||||
| 	return newInitialismNameLexem(original, original) | ||||
| } | ||||
| 
 | ||||
| func (s *splitter) breakCasualString(str []rune) []nameLexem { | ||||
| 	segments := make([]nameLexem, 0) | ||||
| 	currentSegment := "" | ||||
| 
 | ||||
| 	addCasualNameLexem := func(original string) { | ||||
| 		segments = append(segments, newCasualNameLexem(original)) | ||||
| 	} | ||||
| 
 | ||||
| 	addInitialismNameLexem := func(original, match string) { | ||||
| 		segments = append(segments, newInitialismNameLexem(original, match)) | ||||
| 	} | ||||
| 
 | ||||
| 	addNameLexem := func(original string) { | ||||
| 		if s.postSplitInitialismCheck { | ||||
| 			for _, initialism := range s.initialisms { | ||||
| 				if upper(initialism) == upper(original) { | ||||
| 					addInitialismNameLexem(original, initialism) | ||||
| 					return | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		addCasualNameLexem(original) | ||||
| 	} | ||||
| 
 | ||||
| 	for _, rn := range string(str) { | ||||
| 		if replace, found := nameReplaceTable[rn]; found { | ||||
| 			if currentSegment != "" { | ||||
| 				addNameLexem(currentSegment) | ||||
| 				currentSegment = "" | ||||
| 			} | ||||
| 
 | ||||
| 			if replace != "" { | ||||
| 				addNameLexem(replace) | ||||
| 			} | ||||
| 
 | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
| 		if !unicode.In(rn, unicode.L, unicode.M, unicode.N, unicode.Pc) { | ||||
| 			if currentSegment != "" { | ||||
| 				addNameLexem(currentSegment) | ||||
| 				currentSegment = "" | ||||
| 			} | ||||
| 
 | ||||
| 			continue | ||||
| 		} | ||||
| 
 | ||||
| 		if unicode.IsUpper(rn) { | ||||
| 			if currentSegment != "" { | ||||
| 				addNameLexem(currentSegment) | ||||
| 			} | ||||
| 			currentSegment = "" | ||||
| 		} | ||||
| 
 | ||||
| 		currentSegment += string(rn) | ||||
| 	} | ||||
| 
 | ||||
| 	if currentSegment != "" { | ||||
| 		addNameLexem(currentSegment) | ||||
| 	} | ||||
| 
 | ||||
| 	return segments | ||||
| } | ||||
							
								
								
									
										394
									
								
								vendor/github.com/go-openapi/swag/util.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										394
									
								
								vendor/github.com/go-openapi/swag/util.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,394 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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 swag | ||||
| 
 | ||||
| import ( | ||||
| 	"reflect" | ||||
| 	"strings" | ||||
| 	"unicode" | ||||
| ) | ||||
| 
 | ||||
| // commonInitialisms are common acronyms that are kept as whole uppercased words. | ||||
| var commonInitialisms *indexOfInitialisms | ||||
| 
 | ||||
| // initialisms is a slice of sorted initialisms | ||||
| var initialisms []string | ||||
| 
 | ||||
| var isInitialism func(string) bool | ||||
| 
 | ||||
| // GoNamePrefixFunc sets an optional rule to prefix go names | ||||
| // which do not start with a letter. | ||||
| // | ||||
| // e.g. to help convert "123" into "{prefix}123" | ||||
| // | ||||
| // The default is to prefix with "X" | ||||
| var GoNamePrefixFunc func(string) string | ||||
| 
 | ||||
| func init() { | ||||
| 	// Taken from https://github.com/golang/lint/blob/3390df4df2787994aea98de825b964ac7944b817/lint.go#L732-L769 | ||||
| 	var configuredInitialisms = map[string]bool{ | ||||
| 		"ACL":   true, | ||||
| 		"API":   true, | ||||
| 		"ASCII": true, | ||||
| 		"CPU":   true, | ||||
| 		"CSS":   true, | ||||
| 		"DNS":   true, | ||||
| 		"EOF":   true, | ||||
| 		"GUID":  true, | ||||
| 		"HTML":  true, | ||||
| 		"HTTPS": true, | ||||
| 		"HTTP":  true, | ||||
| 		"ID":    true, | ||||
| 		"IP":    true, | ||||
| 		"IPv4":  true, | ||||
| 		"IPv6":  true, | ||||
| 		"JSON":  true, | ||||
| 		"LHS":   true, | ||||
| 		"OAI":   true, | ||||
| 		"QPS":   true, | ||||
| 		"RAM":   true, | ||||
| 		"RHS":   true, | ||||
| 		"RPC":   true, | ||||
| 		"SLA":   true, | ||||
| 		"SMTP":  true, | ||||
| 		"SQL":   true, | ||||
| 		"SSH":   true, | ||||
| 		"TCP":   true, | ||||
| 		"TLS":   true, | ||||
| 		"TTL":   true, | ||||
| 		"UDP":   true, | ||||
| 		"UI":    true, | ||||
| 		"UID":   true, | ||||
| 		"UUID":  true, | ||||
| 		"URI":   true, | ||||
| 		"URL":   true, | ||||
| 		"UTF8":  true, | ||||
| 		"VM":    true, | ||||
| 		"XML":   true, | ||||
| 		"XMPP":  true, | ||||
| 		"XSRF":  true, | ||||
| 		"XSS":   true, | ||||
| 	} | ||||
| 
 | ||||
| 	// a thread-safe index of initialisms | ||||
| 	commonInitialisms = newIndexOfInitialisms().load(configuredInitialisms) | ||||
| 	initialisms = commonInitialisms.sorted() | ||||
| 
 | ||||
| 	// a test function | ||||
| 	isInitialism = commonInitialisms.isInitialism | ||||
| } | ||||
| 
 | ||||
| const ( | ||||
| 	// collectionFormatComma = "csv" | ||||
| 	collectionFormatSpace = "ssv" | ||||
| 	collectionFormatTab   = "tsv" | ||||
| 	collectionFormatPipe  = "pipes" | ||||
| 	collectionFormatMulti = "multi" | ||||
| ) | ||||
| 
 | ||||
| // JoinByFormat joins a string array by a known format (e.g. swagger's collectionFormat attribute): | ||||
| // | ||||
| //	ssv: space separated value | ||||
| //	tsv: tab separated value | ||||
| //	pipes: pipe (|) separated value | ||||
| //	csv: comma separated value (default) | ||||
| func JoinByFormat(data []string, format string) []string { | ||||
| 	if len(data) == 0 { | ||||
| 		return data | ||||
| 	} | ||||
| 	var sep string | ||||
| 	switch format { | ||||
| 	case collectionFormatSpace: | ||||
| 		sep = " " | ||||
| 	case collectionFormatTab: | ||||
| 		sep = "\t" | ||||
| 	case collectionFormatPipe: | ||||
| 		sep = "|" | ||||
| 	case collectionFormatMulti: | ||||
| 		return data | ||||
| 	default: | ||||
| 		sep = "," | ||||
| 	} | ||||
| 	return []string{strings.Join(data, sep)} | ||||
| } | ||||
| 
 | ||||
| // SplitByFormat splits a string by a known format: | ||||
| // | ||||
| //	ssv: space separated value | ||||
| //	tsv: tab separated value | ||||
| //	pipes: pipe (|) separated value | ||||
| //	csv: comma separated value (default) | ||||
| func SplitByFormat(data, format string) []string { | ||||
| 	if data == "" { | ||||
| 		return nil | ||||
| 	} | ||||
| 	var sep string | ||||
| 	switch format { | ||||
| 	case collectionFormatSpace: | ||||
| 		sep = " " | ||||
| 	case collectionFormatTab: | ||||
| 		sep = "\t" | ||||
| 	case collectionFormatPipe: | ||||
| 		sep = "|" | ||||
| 	case collectionFormatMulti: | ||||
| 		return nil | ||||
| 	default: | ||||
| 		sep = "," | ||||
| 	} | ||||
| 	var result []string | ||||
| 	for _, s := range strings.Split(data, sep) { | ||||
| 		if ts := strings.TrimSpace(s); ts != "" { | ||||
| 			result = append(result, ts) | ||||
| 		} | ||||
| 	} | ||||
| 	return result | ||||
| } | ||||
| 
 | ||||
| type byInitialism []string | ||||
| 
 | ||||
| func (s byInitialism) Len() int { | ||||
| 	return len(s) | ||||
| } | ||||
| func (s byInitialism) Swap(i, j int) { | ||||
| 	s[i], s[j] = s[j], s[i] | ||||
| } | ||||
| func (s byInitialism) Less(i, j int) bool { | ||||
| 	if len(s[i]) != len(s[j]) { | ||||
| 		return len(s[i]) < len(s[j]) | ||||
| 	} | ||||
| 
 | ||||
| 	return strings.Compare(s[i], s[j]) > 0 | ||||
| } | ||||
| 
 | ||||
| // Removes leading whitespaces | ||||
| func trim(str string) string { | ||||
| 	return strings.Trim(str, " ") | ||||
| } | ||||
| 
 | ||||
| // Shortcut to strings.ToUpper() | ||||
| func upper(str string) string { | ||||
| 	return strings.ToUpper(trim(str)) | ||||
| } | ||||
| 
 | ||||
| // Shortcut to strings.ToLower() | ||||
| func lower(str string) string { | ||||
| 	return strings.ToLower(trim(str)) | ||||
| } | ||||
| 
 | ||||
| // Camelize an uppercased word | ||||
| func Camelize(word string) (camelized string) { | ||||
| 	for pos, ru := range []rune(word) { | ||||
| 		if pos > 0 { | ||||
| 			camelized += string(unicode.ToLower(ru)) | ||||
| 		} else { | ||||
| 			camelized += string(unicode.ToUpper(ru)) | ||||
| 		} | ||||
| 	} | ||||
| 	return | ||||
| } | ||||
| 
 | ||||
| // ToFileName lowercases and underscores a go type name | ||||
| func ToFileName(name string) string { | ||||
| 	in := split(name) | ||||
| 	out := make([]string, 0, len(in)) | ||||
| 
 | ||||
| 	for _, w := range in { | ||||
| 		out = append(out, lower(w)) | ||||
| 	} | ||||
| 
 | ||||
| 	return strings.Join(out, "_") | ||||
| } | ||||
| 
 | ||||
| // ToCommandName lowercases and underscores a go type name | ||||
| func ToCommandName(name string) string { | ||||
| 	in := split(name) | ||||
| 	out := make([]string, 0, len(in)) | ||||
| 
 | ||||
| 	for _, w := range in { | ||||
| 		out = append(out, lower(w)) | ||||
| 	} | ||||
| 	return strings.Join(out, "-") | ||||
| } | ||||
| 
 | ||||
| // ToHumanNameLower represents a code name as a human series of words | ||||
| func ToHumanNameLower(name string) string { | ||||
| 	in := newSplitter(withPostSplitInitialismCheck).split(name) | ||||
| 	out := make([]string, 0, len(in)) | ||||
| 
 | ||||
| 	for _, w := range in { | ||||
| 		if !w.IsInitialism() { | ||||
| 			out = append(out, lower(w.GetOriginal())) | ||||
| 		} else { | ||||
| 			out = append(out, w.GetOriginal()) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return strings.Join(out, " ") | ||||
| } | ||||
| 
 | ||||
| // ToHumanNameTitle represents a code name as a human series of words with the first letters titleized | ||||
| func ToHumanNameTitle(name string) string { | ||||
| 	in := newSplitter(withPostSplitInitialismCheck).split(name) | ||||
| 
 | ||||
| 	out := make([]string, 0, len(in)) | ||||
| 	for _, w := range in { | ||||
| 		original := w.GetOriginal() | ||||
| 		if !w.IsInitialism() { | ||||
| 			out = append(out, Camelize(original)) | ||||
| 		} else { | ||||
| 			out = append(out, original) | ||||
| 		} | ||||
| 	} | ||||
| 	return strings.Join(out, " ") | ||||
| } | ||||
| 
 | ||||
| // ToJSONName camelcases a name which can be underscored or pascal cased | ||||
| func ToJSONName(name string) string { | ||||
| 	in := split(name) | ||||
| 	out := make([]string, 0, len(in)) | ||||
| 
 | ||||
| 	for i, w := range in { | ||||
| 		if i == 0 { | ||||
| 			out = append(out, lower(w)) | ||||
| 			continue | ||||
| 		} | ||||
| 		out = append(out, Camelize(w)) | ||||
| 	} | ||||
| 	return strings.Join(out, "") | ||||
| } | ||||
| 
 | ||||
| // ToVarName camelcases a name which can be underscored or pascal cased | ||||
| func ToVarName(name string) string { | ||||
| 	res := ToGoName(name) | ||||
| 	if isInitialism(res) { | ||||
| 		return lower(res) | ||||
| 	} | ||||
| 	if len(res) <= 1 { | ||||
| 		return lower(res) | ||||
| 	} | ||||
| 	return lower(res[:1]) + res[1:] | ||||
| } | ||||
| 
 | ||||
| // ToGoName translates a swagger name which can be underscored or camel cased to a name that golint likes | ||||
| func ToGoName(name string) string { | ||||
| 	lexems := newSplitter(withPostSplitInitialismCheck).split(name) | ||||
| 
 | ||||
| 	result := "" | ||||
| 	for _, lexem := range lexems { | ||||
| 		goName := lexem.GetUnsafeGoName() | ||||
| 
 | ||||
| 		// to support old behavior | ||||
| 		if lexem.IsInitialism() { | ||||
| 			goName = upper(goName) | ||||
| 		} | ||||
| 		result += goName | ||||
| 	} | ||||
| 
 | ||||
| 	if len(result) > 0 { | ||||
| 		// Only prefix with X when the first character isn't an ascii letter | ||||
| 		first := []rune(result)[0] | ||||
| 		if !unicode.IsLetter(first) || (first > unicode.MaxASCII && !unicode.IsUpper(first)) { | ||||
| 			if GoNamePrefixFunc == nil { | ||||
| 				return "X" + result | ||||
| 			} | ||||
| 			result = GoNamePrefixFunc(name) + result | ||||
| 		} | ||||
| 		first = []rune(result)[0] | ||||
| 		if unicode.IsLetter(first) && !unicode.IsUpper(first) { | ||||
| 			result = string(append([]rune{unicode.ToUpper(first)}, []rune(result)[1:]...)) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	return result | ||||
| } | ||||
| 
 | ||||
| // ContainsStrings searches a slice of strings for a case-sensitive match | ||||
| func ContainsStrings(coll []string, item string) bool { | ||||
| 	for _, a := range coll { | ||||
| 		if a == item { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
| 
 | ||||
| // ContainsStringsCI searches a slice of strings for a case-insensitive match | ||||
| func ContainsStringsCI(coll []string, item string) bool { | ||||
| 	for _, a := range coll { | ||||
| 		if strings.EqualFold(a, item) { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
| 	return false | ||||
| } | ||||
| 
 | ||||
| type zeroable interface { | ||||
| 	IsZero() bool | ||||
| } | ||||
| 
 | ||||
| // IsZero returns true when the value passed into the function is a zero value. | ||||
| // This allows for safer checking of interface values. | ||||
| func IsZero(data interface{}) bool { | ||||
| 	v := reflect.ValueOf(data) | ||||
| 	// check for nil data | ||||
| 	switch v.Kind() { | ||||
| 	case reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice: | ||||
| 		if v.IsNil() { | ||||
| 			return true | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	// check for things that have an IsZero method instead | ||||
| 	if vv, ok := data.(zeroable); ok { | ||||
| 		return vv.IsZero() | ||||
| 	} | ||||
| 
 | ||||
| 	// continue with slightly more complex reflection | ||||
| 	switch v.Kind() { | ||||
| 	case reflect.String: | ||||
| 		return v.Len() == 0 | ||||
| 	case reflect.Bool: | ||||
| 		return !v.Bool() | ||||
| 	case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: | ||||
| 		return v.Int() == 0 | ||||
| 	case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: | ||||
| 		return v.Uint() == 0 | ||||
| 	case reflect.Float32, reflect.Float64: | ||||
| 		return v.Float() == 0 | ||||
| 	case reflect.Struct, reflect.Array: | ||||
| 		return reflect.DeepEqual(data, reflect.Zero(v.Type()).Interface()) | ||||
| 	case reflect.Invalid: | ||||
| 		return true | ||||
| 	default: | ||||
| 		return false | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // AddInitialisms add additional initialisms | ||||
| func AddInitialisms(words ...string) { | ||||
| 	for _, word := range words { | ||||
| 		// commonInitialisms[upper(word)] = true | ||||
| 		commonInitialisms.add(upper(word)) | ||||
| 	} | ||||
| 	// sort again | ||||
| 	initialisms = commonInitialisms.sorted() | ||||
| } | ||||
| 
 | ||||
| // CommandLineOptionsGroup represents a group of user-defined command line options | ||||
| type CommandLineOptionsGroup struct { | ||||
| 	ShortDescription string | ||||
| 	LongDescription  string | ||||
| 	Options          interface{} | ||||
| } | ||||
							
								
								
									
										450
									
								
								vendor/github.com/go-openapi/swag/yaml.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										450
									
								
								vendor/github.com/go-openapi/swag/yaml.go
									
										
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,450 @@ | |||
| // Copyright 2015 go-swagger maintainers | ||||
| // | ||||
| // 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 swag | ||||
| 
 | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"path/filepath" | ||||
| 	"strconv" | ||||
| 
 | ||||
| 	"github.com/mailru/easyjson/jlexer" | ||||
| 	"github.com/mailru/easyjson/jwriter" | ||||
| 	yaml "gopkg.in/yaml.v3" | ||||
| ) | ||||
| 
 | ||||
| // YAMLMatcher matches yaml | ||||
| func YAMLMatcher(path string) bool { | ||||
| 	ext := filepath.Ext(path) | ||||
| 	return ext == ".yaml" || ext == ".yml" | ||||
| } | ||||
| 
 | ||||
| // YAMLToJSON converts YAML unmarshaled data into json compatible data | ||||
| func YAMLToJSON(data interface{}) (json.RawMessage, error) { | ||||
| 	jm, err := transformData(data) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	b, err := WriteJSON(jm) | ||||
| 	return json.RawMessage(b), err | ||||
| } | ||||
| 
 | ||||
| // BytesToYAMLDoc converts a byte slice into a YAML document | ||||
| func BytesToYAMLDoc(data []byte) (interface{}, error) { | ||||
| 	var document yaml.Node // preserve order that is present in the document | ||||
| 	if err := yaml.Unmarshal(data, &document); err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	if document.Kind != yaml.DocumentNode || len(document.Content) != 1 || document.Content[0].Kind != yaml.MappingNode { | ||||
| 		return nil, fmt.Errorf("only YAML documents that are objects are supported") | ||||
| 	} | ||||
| 	return &document, nil | ||||
| } | ||||
| 
 | ||||
| func yamlNode(root *yaml.Node) (interface{}, error) { | ||||
| 	switch root.Kind { | ||||
| 	case yaml.DocumentNode: | ||||
| 		return yamlDocument(root) | ||||
| 	case yaml.SequenceNode: | ||||
| 		return yamlSequence(root) | ||||
| 	case yaml.MappingNode: | ||||
| 		return yamlMapping(root) | ||||
| 	case yaml.ScalarNode: | ||||
| 		return yamlScalar(root) | ||||
| 	case yaml.AliasNode: | ||||
| 		return yamlNode(root.Alias) | ||||
| 	default: | ||||
| 		return nil, fmt.Errorf("unsupported YAML node type: %v", root.Kind) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func yamlDocument(node *yaml.Node) (interface{}, error) { | ||||
| 	if len(node.Content) != 1 { | ||||
| 		return nil, fmt.Errorf("unexpected YAML Document node content length: %d", len(node.Content)) | ||||
| 	} | ||||
| 	return yamlNode(node.Content[0]) | ||||
| } | ||||
| 
 | ||||
| func yamlMapping(node *yaml.Node) (interface{}, error) { | ||||
| 	m := make(JSONMapSlice, len(node.Content)/2) | ||||
| 
 | ||||
| 	var j int | ||||
| 	for i := 0; i < len(node.Content); i += 2 { | ||||
| 		var nmi JSONMapItem | ||||
| 		k, err := yamlStringScalarC(node.Content[i]) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("unable to decode YAML map key: %w", err) | ||||
| 		} | ||||
| 		nmi.Key = k | ||||
| 		v, err := yamlNode(node.Content[i+1]) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("unable to process YAML map value for key %q: %w", k, err) | ||||
| 		} | ||||
| 		nmi.Value = v | ||||
| 		m[j] = nmi | ||||
| 		j++ | ||||
| 	} | ||||
| 	return m, nil | ||||
| } | ||||
| 
 | ||||
| func yamlSequence(node *yaml.Node) (interface{}, error) { | ||||
| 	s := make([]interface{}, 0) | ||||
| 
 | ||||
| 	for i := 0; i < len(node.Content); i++ { | ||||
| 
 | ||||
| 		v, err := yamlNode(node.Content[i]) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("unable to decode YAML sequence value: %w", err) | ||||
| 		} | ||||
| 		s = append(s, v) | ||||
| 	} | ||||
| 	return s, nil | ||||
| } | ||||
| 
 | ||||
| const ( // See https://yaml.org/type/ | ||||
| 	yamlStringScalar = "tag:yaml.org,2002:str" | ||||
| 	yamlIntScalar    = "tag:yaml.org,2002:int" | ||||
| 	yamlBoolScalar   = "tag:yaml.org,2002:bool" | ||||
| 	yamlFloatScalar  = "tag:yaml.org,2002:float" | ||||
| 	yamlTimestamp    = "tag:yaml.org,2002:timestamp" | ||||
| 	yamlNull         = "tag:yaml.org,2002:null" | ||||
| ) | ||||
| 
 | ||||
| func yamlScalar(node *yaml.Node) (interface{}, error) { | ||||
| 	switch node.LongTag() { | ||||
| 	case yamlStringScalar: | ||||
| 		return node.Value, nil | ||||
| 	case yamlBoolScalar: | ||||
| 		b, err := strconv.ParseBool(node.Value) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("unable to process scalar node. Got %q. Expecting bool content: %w", node.Value, err) | ||||
| 		} | ||||
| 		return b, nil | ||||
| 	case yamlIntScalar: | ||||
| 		i, err := strconv.ParseInt(node.Value, 10, 64) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("unable to process scalar node. Got %q. Expecting integer content: %w", node.Value, err) | ||||
| 		} | ||||
| 		return i, nil | ||||
| 	case yamlFloatScalar: | ||||
| 		f, err := strconv.ParseFloat(node.Value, 64) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("unable to process scalar node. Got %q. Expecting float content: %w", node.Value, err) | ||||
| 		} | ||||
| 		return f, nil | ||||
| 	case yamlTimestamp: | ||||
| 		return node.Value, nil | ||||
| 	case yamlNull: | ||||
| 		return nil, nil | ||||
| 	default: | ||||
| 		return nil, fmt.Errorf("YAML tag %q is not supported", node.LongTag()) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| func yamlStringScalarC(node *yaml.Node) (string, error) { | ||||
| 	if node.Kind != yaml.ScalarNode { | ||||
| 		return "", fmt.Errorf("expecting a string scalar but got %q", node.Kind) | ||||
| 	} | ||||
| 	switch node.LongTag() { | ||||
| 	case yamlStringScalar, yamlIntScalar, yamlFloatScalar: | ||||
| 		return node.Value, nil | ||||
| 	default: | ||||
| 		return "", fmt.Errorf("YAML tag %q is not supported as map key", node.LongTag()) | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| // JSONMapSlice represent a JSON object, with the order of keys maintained | ||||
| type JSONMapSlice []JSONMapItem | ||||
| 
 | ||||
| // MarshalJSON renders a JSONMapSlice as JSON | ||||
| func (s JSONMapSlice) MarshalJSON() ([]byte, error) { | ||||
| 	w := &jwriter.Writer{Flags: jwriter.NilMapAsEmpty | jwriter.NilSliceAsEmpty} | ||||
| 	s.MarshalEasyJSON(w) | ||||
| 	return w.BuildBytes() | ||||
| } | ||||
| 
 | ||||
| // MarshalEasyJSON renders a JSONMapSlice as JSON, using easyJSON | ||||
| 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('}') | ||||
| } | ||||
| 
 | ||||
| // UnmarshalJSON makes a JSONMapSlice from JSON | ||||
| func (s *JSONMapSlice) UnmarshalJSON(data []byte) error { | ||||
| 	l := jlexer.Lexer{Data: data} | ||||
| 	s.UnmarshalEasyJSON(&l) | ||||
| 	return l.Error() | ||||
| } | ||||
| 
 | ||||
| // UnmarshalEasyJSON makes a JSONMapSlice from JSON, using easyJSON | ||||
| 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 | ||||
| } | ||||
| 
 | ||||
| func (s JSONMapSlice) MarshalYAML() (interface{}, error) { | ||||
| 	var n yaml.Node | ||||
| 	n.Kind = yaml.DocumentNode | ||||
| 	var nodes []*yaml.Node | ||||
| 	for _, item := range s { | ||||
| 		nn, err := json2yaml(item.Value) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 		ns := []*yaml.Node{ | ||||
| 			{ | ||||
| 				Kind:  yaml.ScalarNode, | ||||
| 				Tag:   yamlStringScalar, | ||||
| 				Value: item.Key, | ||||
| 			}, | ||||
| 			nn, | ||||
| 		} | ||||
| 		nodes = append(nodes, ns...) | ||||
| 	} | ||||
| 
 | ||||
| 	n.Content = []*yaml.Node{ | ||||
| 		{ | ||||
| 			Kind:    yaml.MappingNode, | ||||
| 			Content: nodes, | ||||
| 		}, | ||||
| 	} | ||||
| 
 | ||||
| 	return yaml.Marshal(&n) | ||||
| } | ||||
| 
 | ||||
| func json2yaml(item interface{}) (*yaml.Node, error) { | ||||
| 	switch val := item.(type) { | ||||
| 	case JSONMapSlice: | ||||
| 		var n yaml.Node | ||||
| 		n.Kind = yaml.MappingNode | ||||
| 		for i := range val { | ||||
| 			childNode, err := json2yaml(&val[i].Value) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 			n.Content = append(n.Content, &yaml.Node{ | ||||
| 				Kind:  yaml.ScalarNode, | ||||
| 				Tag:   yamlStringScalar, | ||||
| 				Value: val[i].Key, | ||||
| 			}, childNode) | ||||
| 		} | ||||
| 		return &n, nil | ||||
| 	case map[string]interface{}: | ||||
| 		var n yaml.Node | ||||
| 		n.Kind = yaml.MappingNode | ||||
| 		for k, v := range val { | ||||
| 			childNode, err := json2yaml(v) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 			n.Content = append(n.Content, &yaml.Node{ | ||||
| 				Kind:  yaml.ScalarNode, | ||||
| 				Tag:   yamlStringScalar, | ||||
| 				Value: k, | ||||
| 			}, childNode) | ||||
| 		} | ||||
| 		return &n, nil | ||||
| 	case []interface{}: | ||||
| 		var n yaml.Node | ||||
| 		n.Kind = yaml.SequenceNode | ||||
| 		for i := range val { | ||||
| 			childNode, err := json2yaml(val[i]) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 			n.Content = append(n.Content, childNode) | ||||
| 		} | ||||
| 		return &n, nil | ||||
| 	case string: | ||||
| 		return &yaml.Node{ | ||||
| 			Kind:  yaml.ScalarNode, | ||||
| 			Tag:   yamlStringScalar, | ||||
| 			Value: val, | ||||
| 		}, nil | ||||
| 	case float64: | ||||
| 		return &yaml.Node{ | ||||
| 			Kind:  yaml.ScalarNode, | ||||
| 			Tag:   yamlFloatScalar, | ||||
| 			Value: strconv.FormatFloat(val, 'f', -1, 64), | ||||
| 		}, nil | ||||
| 	case int64: | ||||
| 		return &yaml.Node{ | ||||
| 			Kind:  yaml.ScalarNode, | ||||
| 			Tag:   yamlIntScalar, | ||||
| 			Value: strconv.FormatInt(val, 10), | ||||
| 		}, nil | ||||
| 	case uint64: | ||||
| 		return &yaml.Node{ | ||||
| 			Kind:  yaml.ScalarNode, | ||||
| 			Tag:   yamlIntScalar, | ||||
| 			Value: strconv.FormatUint(val, 10), | ||||
| 		}, nil | ||||
| 	case bool: | ||||
| 		return &yaml.Node{ | ||||
| 			Kind:  yaml.ScalarNode, | ||||
| 			Tag:   yamlBoolScalar, | ||||
| 			Value: strconv.FormatBool(val), | ||||
| 		}, nil | ||||
| 	} | ||||
| 	return nil, nil | ||||
| } | ||||
| 
 | ||||
| // JSONMapItem represents the value of a key in a JSON object held by JSONMapSlice | ||||
| type JSONMapItem struct { | ||||
| 	Key   string | ||||
| 	Value interface{} | ||||
| } | ||||
| 
 | ||||
| // MarshalJSON renders a JSONMapItem as JSON | ||||
| func (s JSONMapItem) MarshalJSON() ([]byte, error) { | ||||
| 	w := &jwriter.Writer{Flags: jwriter.NilMapAsEmpty | jwriter.NilSliceAsEmpty} | ||||
| 	s.MarshalEasyJSON(w) | ||||
| 	return w.BuildBytes() | ||||
| } | ||||
| 
 | ||||
| // MarshalEasyJSON renders a JSONMapItem as JSON, using easyJSON | ||||
| func (s JSONMapItem) MarshalEasyJSON(w *jwriter.Writer) { | ||||
| 	w.String(s.Key) | ||||
| 	w.RawByte(':') | ||||
| 	w.Raw(WriteJSON(s.Value)) | ||||
| } | ||||
| 
 | ||||
| // UnmarshalJSON makes a JSONMapItem from JSON | ||||
| func (s *JSONMapItem) UnmarshalJSON(data []byte) error { | ||||
| 	l := jlexer.Lexer{Data: data} | ||||
| 	s.UnmarshalEasyJSON(&l) | ||||
| 	return l.Error() | ||||
| } | ||||
| 
 | ||||
| // UnmarshalEasyJSON makes a JSONMapItem from JSON, using easyJSON | ||||
| func (s *JSONMapItem) UnmarshalEasyJSON(in *jlexer.Lexer) { | ||||
| 	key := in.UnsafeString() | ||||
| 	in.WantColon() | ||||
| 	value := in.Interface() | ||||
| 	in.WantComma() | ||||
| 	s.Key = key | ||||
| 	s.Value = value | ||||
| } | ||||
| 
 | ||||
| func transformData(input interface{}) (out interface{}, err error) { | ||||
| 	format := func(t interface{}) (string, error) { | ||||
| 		switch k := t.(type) { | ||||
| 		case string: | ||||
| 			return k, nil | ||||
| 		case uint: | ||||
| 			return strconv.FormatUint(uint64(k), 10), nil | ||||
| 		case uint8: | ||||
| 			return strconv.FormatUint(uint64(k), 10), nil | ||||
| 		case uint16: | ||||
| 			return strconv.FormatUint(uint64(k), 10), nil | ||||
| 		case uint32: | ||||
| 			return strconv.FormatUint(uint64(k), 10), nil | ||||
| 		case uint64: | ||||
| 			return strconv.FormatUint(k, 10), nil | ||||
| 		case int: | ||||
| 			return strconv.Itoa(k), nil | ||||
| 		case int8: | ||||
| 			return strconv.FormatInt(int64(k), 10), nil | ||||
| 		case int16: | ||||
| 			return strconv.FormatInt(int64(k), 10), nil | ||||
| 		case int32: | ||||
| 			return strconv.FormatInt(int64(k), 10), nil | ||||
| 		case int64: | ||||
| 			return strconv.FormatInt(k, 10), nil | ||||
| 		default: | ||||
| 			return "", fmt.Errorf("unexpected map key type, got: %T", k) | ||||
| 		} | ||||
| 	} | ||||
| 
 | ||||
| 	switch in := input.(type) { | ||||
| 	case yaml.Node: | ||||
| 		return yamlNode(&in) | ||||
| 	case *yaml.Node: | ||||
| 		return yamlNode(in) | ||||
| 	case map[interface{}]interface{}: | ||||
| 		o := make(JSONMapSlice, 0, len(in)) | ||||
| 		for ke, va := range in { | ||||
| 			var nmi JSONMapItem | ||||
| 			if nmi.Key, err = format(ke); err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 
 | ||||
| 			v, ert := transformData(va) | ||||
| 			if ert != nil { | ||||
| 				return nil, ert | ||||
| 			} | ||||
| 			nmi.Value = v | ||||
| 			o = append(o, nmi) | ||||
| 		} | ||||
| 		return o, nil | ||||
| 	case []interface{}: | ||||
| 		len1 := len(in) | ||||
| 		o := make([]interface{}, len1) | ||||
| 		for i := 0; i < len1; i++ { | ||||
| 			o[i], err = transformData(in[i]) | ||||
| 			if err != nil { | ||||
| 				return nil, err | ||||
| 			} | ||||
| 		} | ||||
| 		return o, nil | ||||
| 	} | ||||
| 	return input, nil | ||||
| } | ||||
| 
 | ||||
| // YAMLDoc loads a yaml document from either http or a file and converts it to json | ||||
| func YAMLDoc(path string) (json.RawMessage, error) { | ||||
| 	yamlDoc, err := YAMLData(path) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	data, err := YAMLToJSON(yamlDoc) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return data, nil | ||||
| } | ||||
| 
 | ||||
| // YAMLData loads a yaml document from either http or a file | ||||
| func YAMLData(path string) (interface{}, error) { | ||||
| 	data, err := LoadFromFileOrHTTP(path) | ||||
| 	if err != nil { | ||||
| 		return nil, err | ||||
| 	} | ||||
| 
 | ||||
| 	return BytesToYAMLDoc(data) | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue