github.com/gofiber/fiber/v2@v2.47.0/color.go (about)

     1  // ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
     2  // 🤖 Github Repository: https://github.com/gofiber/fiber
     3  // 📌 API Documentation: https://docs.gofiber.io
     4  
     5  package fiber
     6  
     7  // Colors is a struct to define custom colors for Fiber app and middlewares.
     8  type Colors struct {
     9  	// Black color.
    10  	//
    11  	// Optional. Default: "\u001b[90m"
    12  	Black string
    13  
    14  	// Red color.
    15  	//
    16  	// Optional. Default: "\u001b[91m"
    17  	Red string
    18  
    19  	// Green color.
    20  	//
    21  	// Optional. Default: "\u001b[92m"
    22  	Green string
    23  
    24  	// Yellow color.
    25  	//
    26  	// Optional. Default: "\u001b[93m"
    27  	Yellow string
    28  
    29  	// Blue color.
    30  	//
    31  	// Optional. Default: "\u001b[94m"
    32  	Blue string
    33  
    34  	// Magenta color.
    35  	//
    36  	// Optional. Default: "\u001b[95m"
    37  	Magenta string
    38  
    39  	// Cyan color.
    40  	//
    41  	// Optional. Default: "\u001b[96m"
    42  	Cyan string
    43  
    44  	// White color.
    45  	//
    46  	// Optional. Default: "\u001b[97m"
    47  	White string
    48  
    49  	// Reset color.
    50  	//
    51  	// Optional. Default: "\u001b[0m"
    52  	Reset string
    53  }
    54  
    55  // DefaultColors Default color codes
    56  var DefaultColors = Colors{
    57  	Black:   "\u001b[90m",
    58  	Red:     "\u001b[91m",
    59  	Green:   "\u001b[92m",
    60  	Yellow:  "\u001b[93m",
    61  	Blue:    "\u001b[94m",
    62  	Magenta: "\u001b[95m",
    63  	Cyan:    "\u001b[96m",
    64  	White:   "\u001b[97m",
    65  	Reset:   "\u001b[0m",
    66  }
    67  
    68  // defaultColors is a function to override default colors to config
    69  func defaultColors(colors Colors) Colors {
    70  	if colors.Black == "" {
    71  		colors.Black = DefaultColors.Black
    72  	}
    73  
    74  	if colors.Red == "" {
    75  		colors.Red = DefaultColors.Red
    76  	}
    77  
    78  	if colors.Green == "" {
    79  		colors.Green = DefaultColors.Green
    80  	}
    81  
    82  	if colors.Yellow == "" {
    83  		colors.Yellow = DefaultColors.Yellow
    84  	}
    85  
    86  	if colors.Blue == "" {
    87  		colors.Blue = DefaultColors.Blue
    88  	}
    89  
    90  	if colors.Magenta == "" {
    91  		colors.Magenta = DefaultColors.Magenta
    92  	}
    93  
    94  	if colors.Cyan == "" {
    95  		colors.Cyan = DefaultColors.Cyan
    96  	}
    97  
    98  	if colors.White == "" {
    99  		colors.White = DefaultColors.White
   100  	}
   101  
   102  	if colors.Reset == "" {
   103  		colors.Reset = DefaultColors.Reset
   104  	}
   105  
   106  	return colors
   107  }