github.com/kotovmak/go-admin@v1.1.1/plugins/admin/modules/helper.go (about)

     1  package modules
     2  
     3  import (
     4  	"html/template"
     5  	"strconv"
     6  
     7  	"github.com/google/uuid"
     8  )
     9  
    10  func InArray(arr []string, str string) bool {
    11  	for _, v := range arr {
    12  		if v == str {
    13  			return true
    14  		}
    15  	}
    16  	return false
    17  }
    18  
    19  func Delimiter(del, del2, s string) string {
    20  	return del + s + del2
    21  }
    22  
    23  func FilterField(filed, delimiter, delimiter2 string) string {
    24  	return delimiter + filed + delimiter2
    25  }
    26  
    27  func InArrayWithoutEmpty(arr []string, str string) bool {
    28  	if len(arr) == 0 {
    29  		return true
    30  	}
    31  	for _, v := range arr {
    32  		if v == str {
    33  			return true
    34  		}
    35  	}
    36  	return false
    37  }
    38  
    39  func RemoveBlankFromArray(s []string) []string {
    40  	var r []string
    41  	for _, str := range s {
    42  		if str != "" {
    43  			r = append(r, str)
    44  		}
    45  	}
    46  	return r
    47  }
    48  
    49  func Uuid() string {
    50  	return uuid.New().String()
    51  }
    52  
    53  func SetDefault(source, def string) string {
    54  	if source == "" {
    55  		return def
    56  	}
    57  	return source
    58  }
    59  
    60  func GetPage(page string) (pageInt int) {
    61  	if page == "" {
    62  		pageInt = 1
    63  	} else {
    64  		pageInt, _ = strconv.Atoi(page)
    65  	}
    66  	return
    67  }
    68  
    69  func AorB(condition bool, a, b string) string {
    70  	if condition {
    71  		return a
    72  	}
    73  	return b
    74  }
    75  
    76  func AorEmpty(condition bool, a string) string {
    77  	if condition {
    78  		return a
    79  	}
    80  	return ""
    81  }
    82  
    83  func AorBHTML(condition bool, a, b template.HTML) template.HTML {
    84  	if condition {
    85  		return a
    86  	}
    87  	return b
    88  }