...

Source file src/github.com/go-openapi/swag/convert_types.go

Documentation: github.com/go-openapi/swag

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

View as plain text