utils

package
v0.0.0-...-61ee147 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

* Copyright (c) 2024 OceanBase. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDirEmpty

func CheckDirEmpty(path string) error

func CheckDirExists

func CheckDirExists(dir string) error

CheckDirExists checks if the provided filesystem path exists and is a dir. It returns an error if the path does not exist or if the path is not a dir.

func CheckPathExistAndValid

func CheckPathExistAndValid(path string) error

CheckPathExistAndValid checks if the provided filesystem path exists and is valid. It returns an error if the path does not exist or if the path is invalid according to the CheckPathValid function's criteria.

func CheckPathValid

func CheckPathValid(path string) error

CheckPathValid validates the specified path according to several rules. It ensures that the path:

  1. starts with a forward slash ("/"),
  2. matches a specific pattern that includes alphanumeric characters, Chinese characters, certain special characters (-_: @/.), and
  3. does not lead to directory traversal issues when joined with a generated parent path.

func ContainsPrefix

func ContainsPrefix(prefix []string, s string) bool

func ContainsString

func ContainsString(list []string, item string) bool

func Difference

func Difference[T comparable](a, b []T) ([]T, []T)

func IsPortFree

func IsPortFree(port int) (bool, error)

func IsValidIp

func IsValidIp(ip string) bool

func IsValidParamKey

func IsValidParamKey(key string) bool

IsValidParamKey checks whether a parameter key contains only safe characters (letters, digits, and underscores).

func IsValidPort

func IsValidPort(port string) bool

func IsValidPortValue

func IsValidPortValue(p int) bool

func Sha1

func Sha1(input string) string

func ShellQuote

func ShellQuote(s string) string

ShellQuote wraps a string in single quotes with proper escaping for safe use in shell commands. Single quotes inside the string are escaped as '\”.

func SliceEqual

func SliceEqual(list1, list2 []string) bool

Types

type RotateFile

type RotateFile struct {
	// contains filtered or unexported fields
}

func NewRotateFile

func NewRotateFile(fileName string, maxSize int64, maxAge, maxBackups int) *RotateFile

NewRotateFile creates a new RotateFile. The maxSize is the maximum size in megabytes of the log file before it gets rotated. It defaults to 128 megabytes. The maxAge is the maximum number of days to retain old log files based on the timestamp encoded in their filename. If maxAge is 0, old files are not removed. It defaults to 0. The maxBackups is the maximum number of old log files to retain. If maxBackups is 0, all old log files are retained. It defaults to 0.

func (*RotateFile) Close

func (rf *RotateFile) Close() error

func (*RotateFile) Write

func (rf *RotateFile) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL