Documentation
¶
Index ¶
- Constants
- Variables
- func AbsDirPathForExecutable() (string, error)
- func ConvertToXDDDMMM(input string) (string, error)
- func DXCCFromISO2(cc string) (dxcc string, ok bool)
- func DateNowAsYYYYMMDD() string
- func DecodeStringToUTF8(input string) (string, error)
- func DeepCopy(in interface{}, out interface{}) error
- func ExecName(stripExt bool) (string, error)
- func FormatDate(rawDate string) string
- func FormatFrequencyToKhz(rawFreq string) (string, error)
- func FormatFrequencyToMhz(rawFreq string) (string, error)
- func FormatTime(rawTime string) string
- func FrequencyToBand(freq string) string
- func GenerateDateYYYYMMDD(t time.Time) string
- func GetFrequencyRange(freq string) (float64, float64)
- func IsNetworkError(err error) bool
- func IsValidDateYYYYMMDD(s string) bool
- func IsValidFrequencyMHz(s string) bool
- func IsValidTimeADIF(s string) bool
- func IsXDDDMMM(s string) bool
- func NewHTTPClient(httpTimeout time.Duration) *http.Client
- func PathExists(path string) (bool, error)
- func SanitizeDateToYYYYMMDD(s string) string
- func SanitizeTimeToADIF(s string) string
- func SetStructStringField(v interface{}, fieldName string, value string) error
- func WorkingDir(workingDir ...string) (string, error)
- type FIFOList
Constants ¶
const ( // EnvSmWorkingDir is the internal constant name for the environment variable name used to specify // the working directory. EnvSmWorkingDir = "SM_WORKING_DIR" )
Variables ¶
var ( ErrFrequencyTooShort = errors.New("frequency string too short (minimum 9 characters)") ErrFrequencyTooLong = errors.New("frequency string too long (maximum 10 characters)") ErrFrequencySyntax = errors.New("invalid frequency string (must have 2 periods)") ErrFrequencyInvalid = errors.New("invalid frequency string (must have 9 characters)") )
var BandNames = map[string]string{
"54.": "6m",
"53.": "6m",
"52.": "6m",
"51.": "6m",
"50.": "6m",
"29.": "10m",
"28.": "10m",
"24.": "12m",
"21.": "15m",
"18.": "17m",
"14.": "20m",
"10.": "30m",
"7.": "40m",
"5.": "60m",
"3.": "80m",
"2.": "160m",
"1.": "160m",
}
var FrequencyRanges = map[string][2]float64{
"54.": {50.000000, 54.000000},
"53.": {50.000000, 54.000000},
"52.": {50.000000, 54.000000},
"51.": {50.000000, 54.000000},
"50.": {50.000000, 54.000000},
"29.": {28.000000, 29.700000},
"28.": {28.000000, 29.700000},
"24.": {24.890000, 24.990000},
"21.": {21.000000, 21.450000},
"18.": {18.068000, 18.168000},
"14.": {14.000000, 14.350000},
"10.": {10.100000, 10.150000},
"7.": {7.000000, 7.200000},
"5.": {5.351500, 5.366500},
"3.": {3.500000, 3.800000},
"2.": {1.810000, 2.000000},
"1.": {1.810000, 2.000000},
}
FrequencyRanges holds the mapping of frequency prefixes to their min and max ranges.
Functions ¶
func AbsDirPathForExecutable ¶
AbsDirPathForExecutable returns the absolute directory path of the currently running executable.
func ConvertToXDDDMMM ¶
ConvertToXDDDMMM converts a latitude or longitude string to the XDDD°MMM.MMM'N/S/E/W' format and returns the result. It parses the input, calculates degrees and minutes, determines the direction, and formats it accordingly. Returns an error if the input cannot be parsed as a valid floating-point number.
func DXCCFromISO2 ¶
DXCCFromISO2 returns the ADIF DXCC entity code (as a string) for a given two-character ISO 3166-1 alpha-2 country code (case-insensitive).
Notes and caveats:
- ADIF/ARRL DXCC entities do not always map 1:1 to ISO country codes (e.g., the United Kingdom has multiple DXCC entities). Consequently, this function only provides direct, unambiguous mappings for commonly used ISO codes. If a code is not present in the table, the function returns "" and false.
- The mapping can be extended over time as additional needs arise.
Returned values: - dxcc: ADIF DXCC entity code as a string. - ok: true if a mapping was found; otherwise false.
func DateNowAsYYYYMMDD ¶
func DateNowAsYYYYMMDD() string
func DecodeStringToUTF8 ¶
DecodeStringToUTF8 converts a given string to UTF-8 encoding, resolving any encoding issues if possible. Returns the UTF-8 decoded string or an error if the conversion fails.
func DeepCopy ¶
func DeepCopy(in interface{}, out interface{}) error
DeepCopy performs a deep copy of any object using JSON serialization and deserialization. The input `in` is the object to copy, and the output `out` should be a pointer to the desired type.
func ExecName ¶
ExecName returns the name of the current executable, with an option to strip its file extension (if it exists). It resolves symlinks to determine the actual path of the executable when possible. The parameter stripExt specifies whether to remove the file extension from the executable name. It returns the extracted name as a string and an error if retrieval fails. All path components are stripped from the returned name.
func FormatDate ¶
FormatDate converts a raw date string in YYYYMMDD format into a formatted date string in YYYY-MM-DD format. Returns "YYYY-MM-DD" if the input does not have exactly 8 characters.
func FormatFrequencyToKhz ¶
FormatFrequencyToKhz converts a 9-character raw frequency string into a formatted frequency string in kHz format. Returns an error if the input string length is invalid.
func FormatFrequencyToMhz ¶
FormatFrequencyToMhz formats a raw frequency string (e.g., "014.074.000" or "14.074") into MHz format "14.074". It is lenient about length and focuses on dot-separated parts; returns an error if structure is clearly invalid.
func FormatTime ¶
FormatTime converts a 4-digit string representing time in HHMM format to a string in HH:MM format. Returns "HH:MM" on error.
func FrequencyToBand ¶
FrequencyToBand determines the band corresponding to a given frequency string using predefined mappings. It returns the band name if a match is found or an empty string if no match exists.
func GenerateDateYYYYMMDD ¶
func GetFrequencyRange ¶
GetFrequencyRange retrieves the min and max frequency range for a given frequency prefix. It returns the minimum and maximum frequency values if a match is found, or 0, 0 if no match exists.
func IsNetworkError ¶
IsNetworkError determines if an error represents a network-related failure using type assertions and error checking without string matching. This includes timeouts, connection failures, DNS errors, TLS errors, and various syscall network errors.
func IsValidDateYYYYMMDD ¶
IsValidDateYYYYMMDD validates a date string strictly in the format YYYYMMDD. Rules: - exactly 8 digits (no separators) - represents a real calendar date (UTC) including leap years - disallow all-zero date like 00000000
func IsValidFrequencyMHz ¶
func IsValidTimeADIF ¶
IsValidTimeADIF validates an ADIF time string. Accepts: - HHMM (4 digits) - HHMMSS (6 digits) Where HH is 00-23, MM is 00-59, SS is 00-59. Spaces and separators are not allowed.
func IsXDDDMMM ¶
IsXDDDMMM returns true if s matches the XDDD MMM.MMM latitude/longitude format. Acceptable directions: N, S, E, W. Degrees must be zero-padded to 3 digits (000–180), minutes must be zero-padded with exactly two digits before the decimal point and exactly three digits after (00.000–59.999). Note: When degrees = 180, minutes must be 00.000 to be a valid coordinate; this function enforces that.
func PathExists ¶
PathExists checks if a specified file or directory exists at the given path. It resolves symlinks because it uses os.Stat. It returns true if the path exists, false if it does not exist, and an error for permission-related issues or unexpected file system errors.
func SanitizeDateToYYYYMMDD ¶
SanitizeDateToYYYYMMDD converts date strings in formats YYYY-MM-DD or YYYY/MM/DD to YYYYMMDD. If the input is already in YYYYMMDD, it is returned unchanged. Leading/trailing spaces are ignored. Returns empty string if the input cannot be sanitized into a valid YYYYMMDD date.
func SanitizeTimeToADIF ¶
SanitizeTimeToADIF converts a string time into compact ADIF formats HHMM or HHMMSS. Accepted inputs include: - HH:MM, H:MM, HH:MM:SS, H:MM:SS - Plain digits HHMM or HHMMSS - Separators ':', '-', '.', ' ' between parts will be ignored Returns empty string if it cannot be sanitized to a valid time.
func SetStructStringField ¶
SetStructStringField sets the value of a string field in a struct by its field name dynamically using reflection. Requires a pointer to a struct; returns an error if v is not a pointer to a struct, the field does not exist, or cannot be set.
func WorkingDir ¶
WorkingDir determines the working directory path, prioritizing function argument, environment variable, or executable location. It validates the directory exists and returns an absolute path or an error if validation fails.
Types ¶
type FIFOList ¶
type FIFOList[T any] struct { // contains filtered or unexported fields }
func (*FIFOList[T]) Peek ¶
Peek returns the first item without removing it Returns the zero value of T and false if the list is empty