github.com/cilium/cilium@v1.16.2/tools/dev-doctor/envvarcheck.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package main
     5  
     6  import (
     7  	"fmt"
     8  	"os"
     9  	"strings"
    10  )
    11  
    12  // An envVarCheck checks that an environment variable is set and not empty.
    13  type envVarCheck struct {
    14  	name            string
    15  	ifNotSetOrEmpty checkResult
    16  }
    17  
    18  func (c *envVarCheck) Name() string {
    19  	name := c.name
    20  	name = strings.ToLower(name)
    21  	name = strings.Replace(name, "_", "-", -1)
    22  	return name
    23  }
    24  
    25  func (c *envVarCheck) Run() (checkResult, string) {
    26  	if os.Getenv(c.name) == "" {
    27  		return c.ifNotSetOrEmpty, fmt.Sprintf("$%s not set or empty", c.name)
    28  	}
    29  	return checkOK, fmt.Sprintf("$%s is set", c.name)
    30  }
    31  
    32  func (c *envVarCheck) Hint() string {
    33  	return ""
    34  }