utils

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddrCompletion

func AddrCompletion(raw string, ip net.IP, port uint16) string

AddrCompletion convert given raw string to standardized address, if the ip/port part of raw missing, will use ip and port to complete it. if the given ip is nil, treat as 0.0.0.0 "" => ip:port 80 => ip:80 1.1.1.1 => 1.1.1.1:port

func MaxProcessNameLength

func MaxProcessNameLength() int

MaxProcessNameLength returns sum of all string length of elements in os.Args

func RenameMyProcess

func RenameMyProcess(ctx context.Context, name string)

RenameMyProcess overwrite all args in os.Args, the maxium length of new name is equal to length sum of all os.Args. Because of space split between args, the real display mostly like this: e.g. this is a demo. =display=> this i s a demo. You could define a customied encode/decode rules to avoid the problem: e.g. this is a demo. =encode=> this+is+a+demo. =display=> this+i s+a+ demo.

func ResolveTCPAddr

func ResolveTCPAddr(raw string, ip net.IP, port uint16) (*net.TCPAddr, error)

ResolveTCPAddr use AddrCompletion to resolve the raw as a tcp address

func ResolveUDPAddr

func ResolveUDPAddr(raw string, ip net.IP, port uint16) (*net.UDPAddr, error)

ResolveUDPAddr use AddrCompletion to resolve the raw as a udp address

func SimpleContext

func SimpleContext() context.Context

func WritePID

func WritePID(ctx context.Context, file string, pid int) error

WriteMyPID write current process pid to the given file. If write failed, but the file content is equal to current process id, that's also ok.

Types

This section is empty.

Jump to

Keyboard shortcuts

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