Documentation
¶
Overview ¶
Package utils provides some efficient functions.
Index ¶
- func ConvertExcel(filePath, ext string, delimiter rune) error
- func ConvertExcelToCSV(filePath string) error
- func ConvertExcelToTSV(filePath string) error
- func ConvertStringToCharByte(s string) ([]byte, error)
- func ConvertStringToCharRune(s string) (rune, error)
- func CopyByReader(src io.Reader, dst io.Writer, buffer ...[]byte) error
- func CopyFile(src, dst string) error
- func HasNullByte(data []byte) bool
- func HasNullByteInFile(filePath string) (bool, error)
- func HasNullByteInReader(r io.Reader) (bool, error)
- func IsCIDR(i string) bool
- func IsDarwin() bool
- func IsDomain(i any) bool
- func IsIP(i string) bool
- func IsIPv4(i string) bool
- func IsIPv4CIDR(i string) bool
- func IsIPv6(i string) bool
- func IsIPv6CIDR(i string) bool
- func IsLinux() bool
- func IsPathExist(f string) bool
- func IsURL(u string) bool
- func IsWindows() bool
- func JSONMarshal(v any) ([]byte, error)
- func JSONMarshalString(v any) (string, error)
- func JSONUnmarshal(data []byte, v any) error
- func JSONUnmarshalString(data string, v any) error
- func ListFiles(dir, contentType string, fileExteinsion ...string) []string
- func RemoveNullByte(data []byte) []byte
- func RemoveNullByteInFile(filePath string) error
- func RemoveNullByteInReader(reader io.Reader) (io.Reader, error)
- func ReplaceDelimiter(filePath string, old, new string) error
- func ReplaceDosToUnix(filePath string) error
- func SkipFirstRow(f *os.File) error
- func ToInt64(v any) (int64, error)
- func UnZip(zip, dst string) error
- func Version() string
- func Zip(src, zip string) error
- type GoogleMaps
- func (g *GoogleMaps) Directions(req *maps.DirectionsRequest) ([]maps.Route, []maps.GeocodedWaypoint, error)
- func (g *GoogleMaps) DistanceMatrix(req *maps.DistanceMatrixRequest) (*maps.DistanceMatrixResponse, error)
- func (g *GoogleMaps) Elevation(req *maps.ElevationRequest) ([]maps.ElevationResult, error)
- func (g *GoogleMaps) Geocode(req *maps.GeocodingRequest) ([]maps.GeocodingResult, error)
- func (g *GoogleMaps) Geolocate(req *maps.GeolocationRequest) (*maps.GeolocationResult, error)
- func (g *GoogleMaps) PlaceDetails(req *maps.PlaceDetailsRequest) (maps.PlaceDetailsResult, error)
- func (g *GoogleMaps) PlaceNearbySearch(req *maps.NearbySearchRequest) (maps.PlacesSearchResponse, error)
- func (g *GoogleMaps) RoadsNearest(req *maps.NearestRoadsRequest) (*maps.NearestRoadsResponse, error)
- func (g *GoogleMaps) RoadsSnapTo(req *maps.SnapToRoadRequest) (*maps.SnapToRoadResponse, error)
- func (g *GoogleMaps) RoadsSpeedLimits(req *maps.SpeedLimitsRequest) (*maps.SpeedLimitsResponse, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertExcel ¶ added in v0.0.3
ConvertExcelToTSV converts the Excel file to the text file by delimiter.
func ConvertExcelToCSV ¶
ConvertExcelToCSV converts the Excel file to the CSV format file.
func ConvertExcelToTSV ¶
ConvertExcelToTSV converts the Excel file to the TSV format file.
func ConvertStringToCharByte ¶ added in v0.0.2
ConvertStringToCharByte converts the given string(char) to a byte slice, if error returns nil.
func ConvertStringToCharRune ¶ added in v0.0.2
ConvertStringToCharRune converts the given string(char) to rune, if error returns 0 and error.
func CopyByReader ¶
CopyByReader copies the src Reader to the dst Writer.
func HasNullByte ¶ added in v0.0.3
HasNullByteInFile checks the byte slice has the ASCII 0 or not.
Example ¶
package main import ( "fmt" "github.com/linzeyan/utils" ) func main() { type exampleType struct { data []byte } var x = []exampleType{ {[]byte{0, 1, 2, 3}}, {[]byte{44, 55, 00, 77, 88}}, {[]byte{111, 222}}, } for i := range x { fmt.Println(utils.HasNullByte(x[i].data)) } }
Output: true true false
func HasNullByteInFile ¶ added in v0.0.2
HasNullByteInFile checks the file has the ASCII 0, if ReadFile error returns false and error.
func HasNullByteInReader ¶ added in v0.0.2
HasNullByteInReader checks the reader has the ASCII 0, if ReadAll error returns false and error.
func IsIPv4CIDR ¶ added in v0.0.2
IsIPv4CIDR checks if i is a valid IPv4 CIDR.
func IsIPv6CIDR ¶ added in v0.0.2
IsIPv6CIDR checks if i is a valid IPv6 CIDR.
func IsPathExist ¶ added in v0.0.2
IsPathExist checks if f is a valid path.
func JSONMarshal ¶ added in v0.0.3
JSONMarshal returns the JSON encoding bytes of v.
func JSONMarshalString ¶ added in v0.0.3
MarshalString returns the JSON encoding string of v.
func JSONUnmarshal ¶ added in v0.0.3
JSONUnmarshal parses the JSON-encoded data and stores the result in the value pointed to by v.
func JSONUnmarshalString ¶ added in v0.0.3
JSONUnmarshalString is like JSONUnmarshal, except buf is a string.
func ListFiles ¶
ListFiles returns a slice containing file paths for a given content type and file extension.
func RemoveNullByte ¶
RemoveNullByte removes the ASCII 0 in the data.
Example ¶
package main import ( "fmt" "github.com/linzeyan/utils" ) func main() { type exampleType struct { data []byte } var x = []exampleType{ {[]byte{0, 1, 2, 3}}, {[]byte{44, 55, 00, 77, 88}}, {[]byte{111, 222}}, } for i := range x { x[i].data = utils.RemoveNullByte(x[i].data) fmt.Println(utils.HasNullByte(x[i].data), x[i].data) } }
Output: false [1 2 3] false [44 55 77 88] false [111 222]
func RemoveNullByteInFile ¶ added in v0.0.2
RemoveNullByteInFile removes the ASCII 0 in the file.
func RemoveNullByteInReader ¶ added in v0.0.2
RemoveNullByteInReader removes the ASCII 0 in reader.
func ReplaceDelimiter ¶
ReplaceDelimiter replaces the old delimiter with the new delimiter in the filePath.
func ReplaceDosToUnix ¶
ReplaceDosToUnix replaces the Windows end of line(eol) with the Unix eol in the filePath.
func ToInt64 ¶ added in v0.0.2
ToInt64 converts v to int64 value, if input is not numerical, return 0 and error.
Types ¶
type GoogleMaps ¶ added in v0.0.3
func GoogleMapsNewClient ¶ added in v0.0.3
func GoogleMapsNewClient(apiKey string) *GoogleMaps
func (*GoogleMaps) Directions ¶ added in v0.0.3
func (g *GoogleMaps) Directions(req *maps.DirectionsRequest) ([]maps.Route, []maps.GeocodedWaypoint, error)
func (*GoogleMaps) DistanceMatrix ¶ added in v0.0.3
func (g *GoogleMaps) DistanceMatrix(req *maps.DistanceMatrixRequest) (*maps.DistanceMatrixResponse, error)
func (*GoogleMaps) Elevation ¶ added in v0.0.3
func (g *GoogleMaps) Elevation(req *maps.ElevationRequest) ([]maps.ElevationResult, error)
func (*GoogleMaps) Geocode ¶ added in v0.0.3
func (g *GoogleMaps) Geocode(req *maps.GeocodingRequest) ([]maps.GeocodingResult, error)
func (*GoogleMaps) Geolocate ¶ added in v0.0.3
func (g *GoogleMaps) Geolocate(req *maps.GeolocationRequest) (*maps.GeolocationResult, error)
func (*GoogleMaps) PlaceDetails ¶ added in v0.0.3
func (g *GoogleMaps) PlaceDetails(req *maps.PlaceDetailsRequest) (maps.PlaceDetailsResult, error)
func (*GoogleMaps) PlaceNearbySearch ¶ added in v0.0.3
func (g *GoogleMaps) PlaceNearbySearch(req *maps.NearbySearchRequest) (maps.PlacesSearchResponse, error)
func (*GoogleMaps) RoadsNearest ¶ added in v0.0.3
func (g *GoogleMaps) RoadsNearest(req *maps.NearestRoadsRequest) (*maps.NearestRoadsResponse, error)
func (*GoogleMaps) RoadsSnapTo ¶ added in v0.0.3
func (g *GoogleMaps) RoadsSnapTo(req *maps.SnapToRoadRequest) (*maps.SnapToRoadResponse, error)
func (*GoogleMaps) RoadsSpeedLimits ¶ added in v0.0.3
func (g *GoogleMaps) RoadsSpeedLimits(req *maps.SpeedLimitsRequest) (*maps.SpeedLimitsResponse, error)