185 lines
5.5 KiB
Markdown
185 lines
5.5 KiB
Markdown
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
|
|
|
# utils
|
|
|
|
```go
|
|
import "katenary.io/internal/utils"
|
|
```
|
|
|
|
Package utils provides some utility functions used in katenary. It defines some constants and functions used in the whole project.
|
|
|
|
## Constants
|
|
|
|
<a name="DirectoryPermission"></a>DirectoryPermission is the default values for permissions apply to created directories.
|
|
|
|
```go
|
|
const DirectoryPermission = 0o755
|
|
```
|
|
|
|
<a name="AsResourceName"></a>
|
|
## func [AsResourceName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L197>)
|
|
|
|
```go
|
|
func AsResourceName(name string) string
|
|
```
|
|
|
|
AsResourceName returns a resource name with underscores to respect the kubernetes naming convention. It's the opposite of FixedResourceName.
|
|
|
|
<a name="Confirm"></a>
|
|
## func [Confirm](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L165>)
|
|
|
|
```go
|
|
func Confirm(question string, icon ...logger.Icon) bool
|
|
```
|
|
|
|
Confirm asks a question and returns true if the answer is y.
|
|
|
|
<a name="CountStartingSpaces"></a>
|
|
## func [CountStartingSpaces](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L42>)
|
|
|
|
```go
|
|
func CountStartingSpaces(line string) int
|
|
```
|
|
|
|
CountStartingSpaces counts the number of spaces at the beginning of a string.
|
|
|
|
<a name="EncodeBasicYaml"></a>
|
|
## func [EncodeBasicYaml](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L179>)
|
|
|
|
```go
|
|
func EncodeBasicYaml(data any) ([]byte, error)
|
|
```
|
|
|
|
EncodeBasicYaml encodes a basic yaml from an interface.
|
|
|
|
<a name="FixedResourceName"></a>
|
|
## func [FixedResourceName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L191>)
|
|
|
|
```go
|
|
func FixedResourceName(name string) string
|
|
```
|
|
|
|
FixedResourceName returns a resource name without underscores to respect the kubernetes naming convention.
|
|
|
|
<a name="GetContainerByName"></a>
|
|
## func [GetContainerByName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L88>)
|
|
|
|
```go
|
|
func GetContainerByName(name string, containers []corev1.Container) (*corev1.Container, int)
|
|
```
|
|
|
|
GetContainerByName returns a container by name and its index in the array. It returns nil, \-1 if not found.
|
|
|
|
<a name="GetKind"></a>
|
|
## func [GetKind](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L55>)
|
|
|
|
```go
|
|
func GetKind(path string) (kind string)
|
|
```
|
|
|
|
GetKind returns the kind of the resource from the file path.
|
|
|
|
<a name="GetServiceNameByPort"></a>
|
|
## func [GetServiceNameByPort](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L78>)
|
|
|
|
```go
|
|
func GetServiceNameByPort(port int) string
|
|
```
|
|
|
|
GetServiceNameByPort returns the service name for a port. It the service name is not found, it returns an empty string.
|
|
|
|
<a name="GetValuesFromLabel"></a>
|
|
## func [GetValuesFromLabel](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L130>)
|
|
|
|
```go
|
|
func GetValuesFromLabel(service types.ServiceConfig, LabelValues string) map[string]*EnvConfig
|
|
```
|
|
|
|
GetValuesFromLabel returns a map of values from a label.
|
|
|
|
<a name="HashComposefiles"></a>
|
|
## func [HashComposefiles](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/hash.go#L12>)
|
|
|
|
```go
|
|
func HashComposefiles(files []string) (string, error)
|
|
```
|
|
|
|
HashComposefiles returns a hash of the compose files.
|
|
|
|
<a name="Int32Ptr"></a>
|
|
## func [Int32Ptr](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L36>)
|
|
|
|
```go
|
|
func Int32Ptr(i int32) *int32
|
|
```
|
|
|
|
Int32Ptr returns a pointer to an int32.
|
|
|
|
<a name="PathToName"></a>
|
|
## func [PathToName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L107>)
|
|
|
|
```go
|
|
func PathToName(path string) string
|
|
```
|
|
|
|
PathToName converts a path to a kubernetes complient name.
|
|
|
|
<a name="StrPtr"></a>
|
|
## func [StrPtr](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L39>)
|
|
|
|
```go
|
|
func StrPtr(s string) *string
|
|
```
|
|
|
|
StrPtr returns a pointer to a string.
|
|
|
|
<a name="TplName"></a>
|
|
## func [TplName](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L23>)
|
|
|
|
```go
|
|
func TplName(serviceName, appname string, suffix ...string) string
|
|
```
|
|
|
|
TplName returns the name of the kubernetes resource as a template string. It is used in the templates and defined in \_helper.tpl file.
|
|
|
|
<a name="TplValue"></a>
|
|
## func [TplValue](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L98>)
|
|
|
|
```go
|
|
func TplValue(serviceName, variable string, pipes ...string) string
|
|
```
|
|
|
|
TplValue returns a string that can be used in a template to access a value from the values file.
|
|
|
|
<a name="WordWrap"></a>
|
|
## func [WordWrap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L160>)
|
|
|
|
```go
|
|
func WordWrap(text string, lineWidth int) string
|
|
```
|
|
|
|
WordWrap wraps a string to a given line width. Warning: it may break the string. You need to check the result.
|
|
|
|
<a name="Wrap"></a>
|
|
## func [Wrap](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L72>)
|
|
|
|
```go
|
|
func Wrap(src, above, below string) string
|
|
```
|
|
|
|
Wrap wraps a string with a string above and below. It will respect the indentation of the src string.
|
|
|
|
<a name="EnvConfig"></a>
|
|
## type [EnvConfig](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/utils/utils.go#L124-L127>)
|
|
|
|
EnvConfig is a struct to hold the description of an environment variable.
|
|
|
|
```go
|
|
type EnvConfig struct {
|
|
Service types.ServiceConfig
|
|
Description string
|
|
}
|
|
```
|
|
|
|
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|