You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

730 lines
15 KiB

  1. package swag
  2. import "time"
  3. // This file was taken from the aws go sdk
  4. // String returns a pointer to of the string value passed in.
  5. func String(v string) *string {
  6. return &v
  7. }
  8. // StringValue returns the value of the string pointer passed in or
  9. // "" if the pointer is nil.
  10. func StringValue(v *string) string {
  11. if v != nil {
  12. return *v
  13. }
  14. return ""
  15. }
  16. // StringSlice converts a slice of string values into a slice of
  17. // string pointers
  18. func StringSlice(src []string) []*string {
  19. dst := make([]*string, len(src))
  20. for i := 0; i < len(src); i++ {
  21. dst[i] = &(src[i])
  22. }
  23. return dst
  24. }
  25. // StringValueSlice converts a slice of string pointers into a slice of
  26. // string values
  27. func StringValueSlice(src []*string) []string {
  28. dst := make([]string, len(src))
  29. for i := 0; i < len(src); i++ {
  30. if src[i] != nil {
  31. dst[i] = *(src[i])
  32. }
  33. }
  34. return dst
  35. }
  36. // StringMap converts a string map of string values into a string
  37. // map of string pointers
  38. func StringMap(src map[string]string) map[string]*string {
  39. dst := make(map[string]*string)
  40. for k, val := range src {
  41. v := val
  42. dst[k] = &v
  43. }
  44. return dst
  45. }
  46. // StringValueMap converts a string map of string pointers into a string
  47. // map of string values
  48. func StringValueMap(src map[string]*string) map[string]string {
  49. dst := make(map[string]string)
  50. for k, val := range src {
  51. if val != nil {
  52. dst[k] = *val
  53. }
  54. }
  55. return dst
  56. }
  57. // Bool returns a pointer to of the bool value passed in.
  58. func Bool(v bool) *bool {
  59. return &v
  60. }
  61. // BoolValue returns the value of the bool pointer passed in or
  62. // false if the pointer is nil.
  63. func BoolValue(v *bool) bool {
  64. if v != nil {
  65. return *v
  66. }
  67. return false
  68. }
  69. // BoolSlice converts a slice of bool values into a slice of
  70. // bool pointers
  71. func BoolSlice(src []bool) []*bool {
  72. dst := make([]*bool, len(src))
  73. for i := 0; i < len(src); i++ {
  74. dst[i] = &(src[i])
  75. }
  76. return dst
  77. }
  78. // BoolValueSlice converts a slice of bool pointers into a slice of
  79. // bool values
  80. func BoolValueSlice(src []*bool) []bool {
  81. dst := make([]bool, len(src))
  82. for i := 0; i < len(src); i++ {
  83. if src[i] != nil {
  84. dst[i] = *(src[i])
  85. }
  86. }
  87. return dst
  88. }
  89. // BoolMap converts a string map of bool values into a string
  90. // map of bool pointers
  91. func BoolMap(src map[string]bool) map[string]*bool {
  92. dst := make(map[string]*bool)
  93. for k, val := range src {
  94. v := val
  95. dst[k] = &v
  96. }
  97. return dst
  98. }
  99. // BoolValueMap converts a string map of bool pointers into a string
  100. // map of bool values
  101. func BoolValueMap(src map[string]*bool) map[string]bool {
  102. dst := make(map[string]bool)
  103. for k, val := range src {
  104. if val != nil {
  105. dst[k] = *val
  106. }
  107. }
  108. return dst
  109. }
  110. // Int returns a pointer to of the int value passed in.
  111. func Int(v int) *int {
  112. return &v
  113. }
  114. // IntValue returns the value of the int pointer passed in or
  115. // 0 if the pointer is nil.
  116. func IntValue(v *int) int {
  117. if v != nil {
  118. return *v
  119. }
  120. return 0
  121. }
  122. // IntSlice converts a slice of int values into a slice of
  123. // int pointers
  124. func IntSlice(src []int) []*int {
  125. dst := make([]*int, len(src))
  126. for i := 0; i < len(src); i++ {
  127. dst[i] = &(src[i])
  128. }
  129. return dst
  130. }
  131. // IntValueSlice converts a slice of int pointers into a slice of
  132. // int values
  133. func IntValueSlice(src []*int) []int {
  134. dst := make([]int, len(src))
  135. for i := 0; i < len(src); i++ {
  136. if src[i] != nil {
  137. dst[i] = *(src[i])
  138. }
  139. }
  140. return dst
  141. }
  142. // IntMap converts a string map of int values into a string
  143. // map of int pointers
  144. func IntMap(src map[string]int) map[string]*int {
  145. dst := make(map[string]*int)
  146. for k, val := range src {
  147. v := val
  148. dst[k] = &v
  149. }
  150. return dst
  151. }
  152. // IntValueMap converts a string map of int pointers into a string
  153. // map of int values
  154. func IntValueMap(src map[string]*int) map[string]int {
  155. dst := make(map[string]int)
  156. for k, val := range src {
  157. if val != nil {
  158. dst[k] = *val
  159. }
  160. }
  161. return dst
  162. }
  163. // Int32 returns a pointer to of the int32 value passed in.
  164. func Int32(v int32) *int32 {
  165. return &v
  166. }
  167. // Int32Value returns the value of the int32 pointer passed in or
  168. // 0 if the pointer is nil.
  169. func Int32Value(v *int32) int32 {
  170. if v != nil {
  171. return *v
  172. }
  173. return 0
  174. }
  175. // Int32Slice converts a slice of int32 values into a slice of
  176. // int32 pointers
  177. func Int32Slice(src []int32) []*int32 {
  178. dst := make([]*int32, len(src))
  179. for i := 0; i < len(src); i++ {
  180. dst[i] = &(src[i])
  181. }
  182. return dst
  183. }
  184. // Int32ValueSlice converts a slice of int32 pointers into a slice of
  185. // int32 values
  186. func Int32ValueSlice(src []*int32) []int32 {
  187. dst := make([]int32, len(src))
  188. for i := 0; i < len(src); i++ {
  189. if src[i] != nil {
  190. dst[i] = *(src[i])
  191. }
  192. }
  193. return dst
  194. }
  195. // Int32Map converts a string map of int32 values into a string
  196. // map of int32 pointers
  197. func Int32Map(src map[string]int32) map[string]*int32 {
  198. dst := make(map[string]*int32)
  199. for k, val := range src {
  200. v := val
  201. dst[k] = &v
  202. }
  203. return dst
  204. }
  205. // Int32ValueMap converts a string map of int32 pointers into a string
  206. // map of int32 values
  207. func Int32ValueMap(src map[string]*int32) map[string]int32 {
  208. dst := make(map[string]int32)
  209. for k, val := range src {
  210. if val != nil {
  211. dst[k] = *val
  212. }
  213. }
  214. return dst
  215. }
  216. // Int64 returns a pointer to of the int64 value passed in.
  217. func Int64(v int64) *int64 {
  218. return &v
  219. }
  220. // Int64Value returns the value of the int64 pointer passed in or
  221. // 0 if the pointer is nil.
  222. func Int64Value(v *int64) int64 {
  223. if v != nil {
  224. return *v
  225. }
  226. return 0
  227. }
  228. // Int64Slice converts a slice of int64 values into a slice of
  229. // int64 pointers
  230. func Int64Slice(src []int64) []*int64 {
  231. dst := make([]*int64, len(src))
  232. for i := 0; i < len(src); i++ {
  233. dst[i] = &(src[i])
  234. }
  235. return dst
  236. }
  237. // Int64ValueSlice converts a slice of int64 pointers into a slice of
  238. // int64 values
  239. func Int64ValueSlice(src []*int64) []int64 {
  240. dst := make([]int64, len(src))
  241. for i := 0; i < len(src); i++ {
  242. if src[i] != nil {
  243. dst[i] = *(src[i])
  244. }
  245. }
  246. return dst
  247. }
  248. // Int64Map converts a string map of int64 values into a string
  249. // map of int64 pointers
  250. func Int64Map(src map[string]int64) map[string]*int64 {
  251. dst := make(map[string]*int64)
  252. for k, val := range src {
  253. v := val
  254. dst[k] = &v
  255. }
  256. return dst
  257. }
  258. // Int64ValueMap converts a string map of int64 pointers into a string
  259. // map of int64 values
  260. func Int64ValueMap(src map[string]*int64) map[string]int64 {
  261. dst := make(map[string]int64)
  262. for k, val := range src {
  263. if val != nil {
  264. dst[k] = *val
  265. }
  266. }
  267. return dst
  268. }
  269. // Uint16 returns a pointer to of the uint16 value passed in.
  270. func Uint16(v uint16) *uint16 {
  271. return &v
  272. }
  273. // Uint16Value returns the value of the uint16 pointer passed in or
  274. // 0 if the pointer is nil.
  275. func Uint16Value(v *uint16) uint16 {
  276. if v != nil {
  277. return *v
  278. }
  279. return 0
  280. }
  281. // Uint16Slice converts a slice of uint16 values into a slice of
  282. // uint16 pointers
  283. func Uint16Slice(src []uint16) []*uint16 {
  284. dst := make([]*uint16, len(src))
  285. for i := 0; i < len(src); i++ {
  286. dst[i] = &(src[i])
  287. }
  288. return dst
  289. }
  290. // Uint16ValueSlice converts a slice of uint16 pointers into a slice of
  291. // uint16 values
  292. func Uint16ValueSlice(src []*uint16) []uint16 {
  293. dst := make([]uint16, len(src))
  294. for i := 0; i < len(src); i++ {
  295. if src[i] != nil {
  296. dst[i] = *(src[i])
  297. }
  298. }
  299. return dst
  300. }
  301. // Uint16Map converts a string map of uint16 values into a string
  302. // map of uint16 pointers
  303. func Uint16Map(src map[string]uint16) map[string]*uint16 {
  304. dst := make(map[string]*uint16)
  305. for k, val := range src {
  306. v := val
  307. dst[k] = &v
  308. }
  309. return dst
  310. }
  311. // Uint16ValueMap converts a string map of uint16 pointers into a string
  312. // map of uint16 values
  313. func Uint16ValueMap(src map[string]*uint16) map[string]uint16 {
  314. dst := make(map[string]uint16)
  315. for k, val := range src {
  316. if val != nil {
  317. dst[k] = *val
  318. }
  319. }
  320. return dst
  321. }
  322. // Uint returns a pointer to of the uint value passed in.
  323. func Uint(v uint) *uint {
  324. return &v
  325. }
  326. // UintValue returns the value of the uint pointer passed in or
  327. // 0 if the pointer is nil.
  328. func UintValue(v *uint) uint {
  329. if v != nil {
  330. return *v
  331. }
  332. return 0
  333. }
  334. // UintSlice converts a slice of uint values into a slice of
  335. // uint pointers
  336. func UintSlice(src []uint) []*uint {
  337. dst := make([]*uint, len(src))
  338. for i := 0; i < len(src); i++ {
  339. dst[i] = &(src[i])
  340. }
  341. return dst
  342. }
  343. // UintValueSlice converts a slice of uint pointers into a slice of
  344. // uint values
  345. func UintValueSlice(src []*uint) []uint {
  346. dst := make([]uint, len(src))
  347. for i := 0; i < len(src); i++ {
  348. if src[i] != nil {
  349. dst[i] = *(src[i])
  350. }
  351. }
  352. return dst
  353. }
  354. // UintMap converts a string map of uint values into a string
  355. // map of uint pointers
  356. func UintMap(src map[string]uint) map[string]*uint {
  357. dst := make(map[string]*uint)
  358. for k, val := range src {
  359. v := val
  360. dst[k] = &v
  361. }
  362. return dst
  363. }
  364. // UintValueMap converts a string map of uint pointers into a string
  365. // map of uint values
  366. func UintValueMap(src map[string]*uint) map[string]uint {
  367. dst := make(map[string]uint)
  368. for k, val := range src {
  369. if val != nil {
  370. dst[k] = *val
  371. }
  372. }
  373. return dst
  374. }
  375. // Uint32 returns a pointer to of the uint32 value passed in.
  376. func Uint32(v uint32) *uint32 {
  377. return &v
  378. }
  379. // Uint32Value returns the value of the uint32 pointer passed in or
  380. // 0 if the pointer is nil.
  381. func Uint32Value(v *uint32) uint32 {
  382. if v != nil {
  383. return *v
  384. }
  385. return 0
  386. }
  387. // Uint32Slice converts a slice of uint32 values into a slice of
  388. // uint32 pointers
  389. func Uint32Slice(src []uint32) []*uint32 {
  390. dst := make([]*uint32, len(src))
  391. for i := 0; i < len(src); i++ {
  392. dst[i] = &(src[i])
  393. }
  394. return dst
  395. }
  396. // Uint32ValueSlice converts a slice of uint32 pointers into a slice of
  397. // uint32 values
  398. func Uint32ValueSlice(src []*uint32) []uint32 {
  399. dst := make([]uint32, len(src))
  400. for i := 0; i < len(src); i++ {
  401. if src[i] != nil {
  402. dst[i] = *(src[i])
  403. }
  404. }
  405. return dst
  406. }
  407. // Uint32Map converts a string map of uint32 values into a string
  408. // map of uint32 pointers
  409. func Uint32Map(src map[string]uint32) map[string]*uint32 {
  410. dst := make(map[string]*uint32)
  411. for k, val := range src {
  412. v := val
  413. dst[k] = &v
  414. }
  415. return dst
  416. }
  417. // Uint32ValueMap converts a string map of uint32 pointers into a string
  418. // map of uint32 values
  419. func Uint32ValueMap(src map[string]*uint32) map[string]uint32 {
  420. dst := make(map[string]uint32)
  421. for k, val := range src {
  422. if val != nil {
  423. dst[k] = *val
  424. }
  425. }
  426. return dst
  427. }
  428. // Uint64 returns a pointer to of the uint64 value passed in.
  429. func Uint64(v uint64) *uint64 {
  430. return &v
  431. }
  432. // Uint64Value returns the value of the uint64 pointer passed in or
  433. // 0 if the pointer is nil.
  434. func Uint64Value(v *uint64) uint64 {
  435. if v != nil {
  436. return *v
  437. }
  438. return 0
  439. }
  440. // Uint64Slice converts a slice of uint64 values into a slice of
  441. // uint64 pointers
  442. func Uint64Slice(src []uint64) []*uint64 {
  443. dst := make([]*uint64, len(src))
  444. for i := 0; i < len(src); i++ {
  445. dst[i] = &(src[i])
  446. }
  447. return dst
  448. }
  449. // Uint64ValueSlice converts a slice of uint64 pointers into a slice of
  450. // uint64 values
  451. func Uint64ValueSlice(src []*uint64) []uint64 {
  452. dst := make([]uint64, len(src))
  453. for i := 0; i < len(src); i++ {
  454. if src[i] != nil {
  455. dst[i] = *(src[i])
  456. }
  457. }
  458. return dst
  459. }
  460. // Uint64Map converts a string map of uint64 values into a string
  461. // map of uint64 pointers
  462. func Uint64Map(src map[string]uint64) map[string]*uint64 {
  463. dst := make(map[string]*uint64)
  464. for k, val := range src {
  465. v := val
  466. dst[k] = &v
  467. }
  468. return dst
  469. }
  470. // Uint64ValueMap converts a string map of uint64 pointers into a string
  471. // map of uint64 values
  472. func Uint64ValueMap(src map[string]*uint64) map[string]uint64 {
  473. dst := make(map[string]uint64)
  474. for k, val := range src {
  475. if val != nil {
  476. dst[k] = *val
  477. }
  478. }
  479. return dst
  480. }
  481. // Float32 returns a pointer to of the float32 value passed in.
  482. func Float32(v float32) *float32 {
  483. return &v
  484. }
  485. // Float32Value returns the value of the float32 pointer passed in or
  486. // 0 if the pointer is nil.
  487. func Float32Value(v *float32) float32 {
  488. if v != nil {
  489. return *v
  490. }
  491. return 0
  492. }
  493. // Float32Slice converts a slice of float32 values into a slice of
  494. // float32 pointers
  495. func Float32Slice(src []float32) []*float32 {
  496. dst := make([]*float32, len(src))
  497. for i := 0; i < len(src); i++ {
  498. dst[i] = &(src[i])
  499. }
  500. return dst
  501. }
  502. // Float32ValueSlice converts a slice of float32 pointers into a slice of
  503. // float32 values
  504. func Float32ValueSlice(src []*float32) []float32 {
  505. dst := make([]float32, len(src))
  506. for i := 0; i < len(src); i++ {
  507. if src[i] != nil {
  508. dst[i] = *(src[i])
  509. }
  510. }
  511. return dst
  512. }
  513. // Float32Map converts a string map of float32 values into a string
  514. // map of float32 pointers
  515. func Float32Map(src map[string]float32) map[string]*float32 {
  516. dst := make(map[string]*float32)
  517. for k, val := range src {
  518. v := val
  519. dst[k] = &v
  520. }
  521. return dst
  522. }
  523. // Float32ValueMap converts a string map of float32 pointers into a string
  524. // map of float32 values
  525. func Float32ValueMap(src map[string]*float32) map[string]float32 {
  526. dst := make(map[string]float32)
  527. for k, val := range src {
  528. if val != nil {
  529. dst[k] = *val
  530. }
  531. }
  532. return dst
  533. }
  534. // Float64 returns a pointer to of the float64 value passed in.
  535. func Float64(v float64) *float64 {
  536. return &v
  537. }
  538. // Float64Value returns the value of the float64 pointer passed in or
  539. // 0 if the pointer is nil.
  540. func Float64Value(v *float64) float64 {
  541. if v != nil {
  542. return *v
  543. }
  544. return 0
  545. }
  546. // Float64Slice converts a slice of float64 values into a slice of
  547. // float64 pointers
  548. func Float64Slice(src []float64) []*float64 {
  549. dst := make([]*float64, len(src))
  550. for i := 0; i < len(src); i++ {
  551. dst[i] = &(src[i])
  552. }
  553. return dst
  554. }
  555. // Float64ValueSlice converts a slice of float64 pointers into a slice of
  556. // float64 values
  557. func Float64ValueSlice(src []*float64) []float64 {
  558. dst := make([]float64, len(src))
  559. for i := 0; i < len(src); i++ {
  560. if src[i] != nil {
  561. dst[i] = *(src[i])
  562. }
  563. }
  564. return dst
  565. }
  566. // Float64Map converts a string map of float64 values into a string
  567. // map of float64 pointers
  568. func Float64Map(src map[string]float64) map[string]*float64 {
  569. dst := make(map[string]*float64)
  570. for k, val := range src {
  571. v := val
  572. dst[k] = &v
  573. }
  574. return dst
  575. }
  576. // Float64ValueMap converts a string map of float64 pointers into a string
  577. // map of float64 values
  578. func Float64ValueMap(src map[string]*float64) map[string]float64 {
  579. dst := make(map[string]float64)
  580. for k, val := range src {
  581. if val != nil {
  582. dst[k] = *val
  583. }
  584. }
  585. return dst
  586. }
  587. // Time returns a pointer to of the time.Time value passed in.
  588. func Time(v time.Time) *time.Time {
  589. return &v
  590. }
  591. // TimeValue returns the value of the time.Time pointer passed in or
  592. // time.Time{} if the pointer is nil.
  593. func TimeValue(v *time.Time) time.Time {
  594. if v != nil {
  595. return *v
  596. }
  597. return time.Time{}
  598. }
  599. // TimeSlice converts a slice of time.Time values into a slice of
  600. // time.Time pointers
  601. func TimeSlice(src []time.Time) []*time.Time {
  602. dst := make([]*time.Time, len(src))
  603. for i := 0; i < len(src); i++ {
  604. dst[i] = &(src[i])
  605. }
  606. return dst
  607. }
  608. // TimeValueSlice converts a slice of time.Time pointers into a slice of
  609. // time.Time values
  610. func TimeValueSlice(src []*time.Time) []time.Time {
  611. dst := make([]time.Time, len(src))
  612. for i := 0; i < len(src); i++ {
  613. if src[i] != nil {
  614. dst[i] = *(src[i])
  615. }
  616. }
  617. return dst
  618. }
  619. // TimeMap converts a string map of time.Time values into a string
  620. // map of time.Time pointers
  621. func TimeMap(src map[string]time.Time) map[string]*time.Time {
  622. dst := make(map[string]*time.Time)
  623. for k, val := range src {
  624. v := val
  625. dst[k] = &v
  626. }
  627. return dst
  628. }
  629. // TimeValueMap converts a string map of time.Time pointers into a string
  630. // map of time.Time values
  631. func TimeValueMap(src map[string]*time.Time) map[string]time.Time {
  632. dst := make(map[string]time.Time)
  633. for k, val := range src {
  634. if val != nil {
  635. dst[k] = *val
  636. }
  637. }
  638. return dst
  639. }