diff --git a/.gitattributes b/.gitattributes index 6313b56..5ea9f7d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ * text=auto eol=lf +*.go -text diff=golang \ No newline at end of file diff --git a/constant.go b/constants.go similarity index 100% rename from constant.go rename to constants.go diff --git a/docs/docs/.vitepress/config.ts b/docs/docs/.vitepress/config.ts index 408a894..e013c16 100644 --- a/docs/docs/.vitepress/config.ts +++ b/docs/docs/.vitepress/config.ts @@ -51,6 +51,12 @@ export default defineConfig({ ], }, ], + search: { + provider: "local", + options: { + detailedView: true, + }, + }, sidebar: { "/introduction/": { @@ -73,6 +79,7 @@ export default defineConfig({ { text: "โŒ› Cron", link: "cron" }, { text: "๐Ÿ” Crypto", link: "crypto" }, { text: "๐Ÿ“… Date", link: "date" }, + { text: "โŒ› Time", link: "time" }, { text: "๐Ÿซ› Function", link: "function" }, { text: "๐ŸŽฏ I/O", link: "io" }, { text: "โœ๏ธ Log", link: "log" }, @@ -85,9 +92,10 @@ export default defineConfig({ { text: "๐Ÿ”ƒ Regex", link: "regex" }, { text: "๐Ÿ”— String", link: "string" }, { text: "๐Ÿ›ณ๏ธ Struct", link: "struct" }, - { text: "๐Ÿง Type", link: "type" }, + { text: "๐Ÿ“š Type", link: "type" }, - // { text: 'Path', link: 'path' }, + // { text: "๐Ÿ“ง Email", link: "email" }, + // { text: '๐ŸงPath', link: 'path' }, // { text: 'Security', link: 'security' }, // { text: 'Web', link: 'web' }, // { text: 'Worker', link: 'worker' }, diff --git a/docs/docs/public/doc_preview.png b/docs/docs/public/doc_preview.png index a5364f6..2fa2f37 100644 Binary files a/docs/docs/public/doc_preview.png and b/docs/docs/public/doc_preview.png differ diff --git a/samples/api.go b/samples/api.go index 74993bd..b33d752 100644 --- a/samples/api.go +++ b/samples/api.go @@ -10,7 +10,7 @@ import ( Description: Load balancer with health check Input params: (ILbConfig.ProxyPort, ILbConfig.Backends) */ -func ApiLoadbalancer() { +func Loadbalancer() { lbCfg := gouse.ILbConfig{ ProxyPort: "8080", Backends: []gouse.IBackend{ @@ -37,7 +37,7 @@ func ApiLoadbalancer() { Description: Graceful shutdown for API server Input params: (IGracefulShutdown) */ -func ApiGracefulShutdown() { +func GracefulShutdown() { gs := gouse.IGracefulShutdown{ Port: "3000", StartMsg: "Starting server at port http://localhost:3000", diff --git a/samples/chart.go b/samples/chart.go index 101af3c..62ed1da 100644 --- a/samples/chart.go +++ b/samples/chart.go @@ -6,6 +6,7 @@ import ( /* Description: Create a bar chart and export it to a html file +Input params: (*gouse.IBarChartOpts) */ func ChartBar() { newChart := &gouse.IBarChartOpts{ @@ -25,6 +26,7 @@ func ChartBar() { /* Description: Create a line chart and export it to a html file +Input params: (*gouse.ILineChartOpts) */ func ChartLine() { newChart := &gouse.ILineChartOpts{ @@ -43,6 +45,7 @@ func ChartLine() { /* Description: Create a pie chart and export it to a html file +Input params: (*gouse.IPieChartOpts) */ func ChartPie() { newChart := &gouse.IPieChartOpts{ diff --git a/samples/config.go b/samples/config.go index 226f46d..8b6c994 100644 --- a/samples/config.go +++ b/samples/config.go @@ -8,6 +8,7 @@ import ( /* Description: Read JSON configuration file +Input params: (path string, v interface{}) */ func ConfigJson() { type configuration struct { @@ -27,6 +28,7 @@ func ConfigJson() { /* Description: Read TOML configuration file +Input params: (path string, v interface{}) */ func ConfigToml() { type configuration struct { @@ -52,6 +54,7 @@ func ConfigToml() { /* Description: Read YAML configuration file +Input params: (path string, v interface{}) */ func ConfigYaml() { type configuration struct { diff --git a/samples/console.go b/samples/console.go index 95eae10..f249072 100644 --- a/samples/console.go +++ b/samples/console.go @@ -24,6 +24,10 @@ import ( "github.com/thuongtruong109/gouse/cookbook/console/table" ) +/* +Description: Run a command in the console +Input params: (...command string) +*/ func ConsoleCmd() { gouse.Cmd("echo command is working") @@ -31,12 +35,19 @@ func ConsoleCmd() { gouse.Cmd("ls", "clear") } +/* +Description: Clear the console +*/ func ConsoleClear() { println("console will be cleared now") gouse.Cls() println("console cleared") } +/* +Description: Print with color in the console +Input params: (color string, text string) +*/ func ConsoleWithColor() { gouse.OutputColor(gouse.DEFAULT_CONSOLE, "this is default") gouse.OutputColor(gouse.WHITE_CONSOLE, "this is white") @@ -48,12 +59,19 @@ func ConsoleWithColor() { gouse.OutputColor(gouse.CYAN_CONSOLE, "this is cyan") } +/* +Description: Display a banner in the console +Input params: (font string, text string) +*/ func ConsoleBanner() { - // param1: font name, param2: your input string gouse.Banner(gouse.DOUBLE_ALPHA, "gouse - type double") gouse.Banner(gouse.DOUBLE_ALPHA, "gouse - type single") } +/* +Description: Display a help menu in the console +Input params: (name string, options []*gouse.IHelpOptions) +*/ func ConsoleHelp() { name := "myprogram" options := []*gouse.IHelpOptions{ @@ -88,6 +106,9 @@ func ConsoleHelp() { // } } +/* +Description: Display a select menu in the console +*/ func ConsoleSelect() { optconsolens := []string{"a", "b", "c"} selected, err := gouse.Select("Select an optconsolen:", optconsolens) diff --git a/samples/crypto.go b/samples/crypto.go index af6f11a..5d52651 100644 --- a/samples/crypto.go +++ b/samples/crypto.go @@ -10,7 +10,7 @@ import ( Description: Encode data to base64 Input params: (data []byte) */ -func CryptoEncode() { +func EncodeData() { data := []byte("This is a sample data") encodedData, err := gouse.EncodeData(data) @@ -26,7 +26,7 @@ func CryptoEncode() { Description: Decode data from base64 Input params: (data []byte) */ -func CryptoDecode() { +func DecodeData() { data := []byte("VGhpcyBpcyBhIHNhbXBsZSBkYXRh") decodedData, err := gouse.DecodeData(data) if err != nil { @@ -41,7 +41,7 @@ func CryptoDecode() { Description: Encrypt data in file Input params: (filename string, password []byte) */ -func CryptoEncryptFile() { +func EncryptFile() { gouse.EncryptFile("sample.txt", []byte("password")) println("File content encrypted") } @@ -50,7 +50,7 @@ func CryptoEncryptFile() { Description: Decrypt data in file Input params: (filename string, password []byte) */ -func CryptoDecryptFile() { +func DecryptFile() { gouse.DecryptFile("sample.txt", []byte("password")) println("File content decrypted") } @@ -59,7 +59,7 @@ func CryptoDecryptFile() { Description: Encrypt password string Input params: (data string) */ -func CryptoEncryptPassword() { +func EncryptPassword() { data := "This is a sample data" encryptedData, err := gouse.EncryptPassword(data) @@ -75,7 +75,7 @@ func CryptoEncryptPassword() { Description: Decrypt password string and compare with the original password Input params: (data string, password string) */ -func CryptoDecryptPassword() { +func DecryptPassword() { data := "$2a$10$bcA002IOHi5SYHNH4lmIbuHjHplGl7TQZ.MznNrL1N70vAi7ovTa2" err := gouse.DecryptPassword(data, "This is a sample data") if err != nil { diff --git a/samples/date.go b/samples/date.go index f248ec8..e0ca76b 100644 --- a/samples/date.go +++ b/samples/date.go @@ -1,32 +1,17 @@ package samples -import ( - "fmt" - - "github.com/thuongtruong109/gouse" -) - -func DateTime() { - println("Second:", gouse.Second()) - println("Minute:", gouse.Minute()) - println("Hour:", gouse.Hour()) - println("Day:", gouse.Day()) - println("Month:", gouse.Month()) - println("Year:", gouse.Year()) - println("Weekday:", gouse.Weekday()) - println("Unix:", gouse.Unix()) - println("UnixNano:", gouse.UnixNano()) - println("UnixMilli:", gouse.UnixMilli()) - println("UnixMicro:", gouse.UnixMicro()) - fmt.Println("UnixMilliToTime:", gouse.UnixMilliToTime(1000000000)) - fmt.Println("UnixMicroToTime:", gouse.UnixMicroToTime(1000000000)) - fmt.Println("UnixNanoToTime:", gouse.UnixNanoToTime(1000000000)) -} +import "github.com/thuongtruong109/gouse" +/* +Description: Get current date in ISO format +*/ func DateISO() { println("ISO:", gouse.ISODate()) } +/* +Description: Get current date in short formats +*/ func DateShort() { println("ShortNormal:", gouse.NormalDate()) println("ShortReverse:", gouse.ReverseDate()) @@ -37,38 +22,17 @@ func DateShort() { println("ShortMonth:", gouse.MonthDate()) } +/* +Description: Get current date in long format +*/ func DateLong() { println("Long:", gouse.LongDate()) } +/* +Description: Get current date in UTC format +*/ func DateUTC() { println("UTC:", gouse.UTCDate()) } -func DateToSecond() { - println("ToSecond:", gouse.ToSecond(1)) -} - -func DateToMinute() { - println("ToMinute:", gouse.ToMinute(1)) -} - -func DateToHour() { - println("ToHour:", gouse.ToHour(1)) -} - -func DateSleepSecond() { - gouse.SleepSecond(1) -} - -func DateSleepMinute() { - gouse.SleepMinute(1) -} - -func DateSleepHour() { - gouse.SleepHour(1) -} - -func DateClock() { - gouse.TerminalClock() -} diff --git a/samples/function.go b/samples/function.go index 0693910..4b18d7b 100644 --- a/samples/function.go +++ b/samples/function.go @@ -7,7 +7,11 @@ import ( "github.com/thuongtruong109/gouse" ) -func FuncDelay() { +/* +Description: Delay function execution for a specific time. +Input params: (func() string, delay int) +*/ +func FunctionDelay() { println("Delay start:") result := gouse.DelayF(func() string { @@ -25,17 +29,24 @@ func FuncDelay() { }, 3) } -func FuncInterval() { +/* +Description: Execute function at a specific interval. +Input params: (func(), interval int) +*/ +func FunctionInterval() { gouse.IntervalFunc(func() { println("Interval") }, 1) } -func FuncLock() { +/* +Description: Lock function execution. +*/ +func FunctionLock() { oneInOneOutLockFunc := gouse.LockFunc(func(i interface{}) interface{} { return i }).(func(interface{}) interface{})("one input - one output") - fmt.Println(oneInOneOutLockFunc) + gouse.Println(oneInOneOutLockFunc) twoInTwoOutLockFunc1, twoInTwoOutLockFunc2 := gouse.LockFunc(func(i1, i2 interface{}) (interface{}, interface{}) { return i1, i2 @@ -55,72 +66,82 @@ func FuncLock() { fmt.Println("RW Lock function result:", result) } -func FuncParallel() { +/* +Description: Parallelize multi functions execution. +Input params: (...func()) +*/ +func FunctionParallel() { function1 := func() { for i := 0; i < 5; i++ { time.Sleep(100 * time.Millisecond) - fmt.Println("Function 1 is executing") + gouse.Println("Function 1 is executing") } } function2 := func() { for i := 0; i < 5; i++ { time.Sleep(200 * time.Millisecond) - fmt.Println("Function 2 is executing") + gouse.Println("Function 2 is executing") } } function3 := func() { for i := 0; i < 5; i++ { time.Sleep(300 * time.Millisecond) - fmt.Println("Function 3 is executing") + gouse.Println("Function 3 is executing") } } gouse.ParallelizeFunc(function1, function2, function3) } -func FuncRemain() { +/* +Description: Limit function execution. +Input params: (func(), times int) +*/ +func FunctionRemain() { gouse.RemainFunc(func() { println("Times") }, 3) } -func FuncRetry() { +/* +Description: Retry function execution. +Input params: (func(), times int, delay int) +*/ +func FunctionRetry() { gouse.RetryFunc(func() error { println("Retry") return nil }, 3, 1) } -func FuncRunTime() { +/* +Description: Measure function execution time. +Input params: (time.Time, func()) +*/ +func FunctionRunTime() { exampleFunc := func() { time.Sleep(2 * time.Second) - fmt.Println("Task completed.") + gouse.Println("Task completed.") } duration := gouse.RunTimeFunc(time.Now(), exampleFunc) - fmt.Printf("Function run in: %v\n", duration) + gouse.Printf("Function run in: %v\n", duration) } +/* +Description: Wrap defer function +Input params: (...func()) +*/ func FuncDeferWrapper() { gouse.DeferWrapper( func() error { - fmt.Println("Opening file...") - return fmt.Errorf("failed to read file") - }, - func() { - fmt.Println("Closing file...") - }, - ) - - gouse.DeferWrapper( - func() error { - fmt.Println("Connecting to database...") + gouse.Println("Connecting to database...") return nil }, func() { - fmt.Println("Disconnecting from database...") + gouse.Println("Disconnecting from database...") }, ) } diff --git a/samples/helper.go b/samples/helper.go index 9326ec5..3992c38 100644 --- a/samples/helper.go +++ b/samples/helper.go @@ -2,15 +2,18 @@ package samples import "github.com/thuongtruong109/gouse" -func HelperRandomID() { - println("Generate random ID: ", gouse.RandID()) -} - -func HelperUUID() { +/* +Description: Generate a new UUID +*/ +func UUID() { println("New uuid: ", gouse.UUID()) } -func HelperAutoMdDoc() { +/* +Description: Auto generate markdown document from go source code +Input params: (inputFilePath: string, outputFilePath: string) +*/ +func AutoMarkdownDocument() { inputFilePath := "main.go" outputFilePath := "main.md" gouse.Go2Md(inputFilePath, outputFilePath) diff --git a/samples/io.go b/samples/io.go index c4a34f4..d816815 100644 --- a/samples/io.go +++ b/samples/io.go @@ -8,8 +8,11 @@ import ( "github.com/thuongtruong109/gouse" ) -/* Samples for io path functions */ -func IoCreatePath() { +/* +Description: Create a path where file to be created. +Input params: (path string) +*/ +func CreatePath() { relativePath := "tmp/example.txt" if err := gouse.CreatePath(relativePath); err != nil { @@ -19,7 +22,11 @@ func IoCreatePath() { println("File created successfully.") } -func IoReadPath() { +/* +Description: Read the path where file to be read. +Input params: (path string) +*/ +func ReadPath() { relativePath := "tmp/example.txt" content, err := gouse.ReadPath(relativePath) @@ -30,7 +37,11 @@ func IoReadPath() { fmt.Println("File content:", string(content)) } -func IoWritePath() { +/* +Description: Write content to the path where file to be updated. +Input params: (path string, content []byte) +*/ +func WritePath() { relativePath := "tmp/example.txt" newContent := []byte("This is a new content") @@ -42,9 +53,11 @@ func IoWritePath() { println("File updated successfully.") } -/* Directory functions */ - -func IoCreateDir() { +/* +Description: Create folder. +Input params: (folderName string) +*/ +func CreateDir() { err2 := gouse.CreateDir("tmp") if err2 != nil { println(err2.Error()) @@ -52,7 +65,10 @@ func IoCreateDir() { println("dir created") } -func IoCurrentDir() { +/* +Description: Get current folder. +*/ +func CurrentDir() { data, err := gouse.CurrentDir() if err != nil { println(err.Error()) @@ -62,7 +78,11 @@ func IoCurrentDir() { println(data) } -func IoHierarchyDir() { +/* +Description: Get the folder hierarchy. +Input params: (position string) +*/ +func HierarchyDir() { data, err := gouse.HierarchyDir(".") if err != nil { println(err.Error()) @@ -74,7 +94,11 @@ func IoHierarchyDir() { } } -func IoCheckDir() { +/* +Description: Check if the folder exists. +Input params: (dirName string) +*/ +func CheckDir() { isExist, err1 := gouse.IsExistDir("tmp") if err1 != nil { println(err1.Error()) @@ -86,7 +110,11 @@ func IoCheckDir() { } } -func IoLsDir() { +/* +Description: List all files in the folder. +Input params: (position string) +*/ +func LsDir() { data, err := gouse.LsDir(".") if err != nil { println(err.Error()) @@ -98,7 +126,11 @@ func IoLsDir() { } } -func IoRemoveDir() { +/* +Description: Remove folder. +Input params: (dirName string) +*/ +func RemoveDir() { err3 := gouse.RemoveDir("tmp") if err3 != nil { println(err3.Error()) @@ -106,9 +138,11 @@ func IoRemoveDir() { println("dir removed") } -/* File functions */ - -func IoAppendToFile() { +/* +Description: Append data to the file. +Input params: (fileName string, data []string) +*/ +func AppendToFile() { err := gouse.AppendFile("data.json", []string{"this is data 3", "this is data 4"}) if err != nil { println(err.Error()) @@ -116,7 +150,11 @@ func IoAppendToFile() { println("file appended") } -func IoCleanFile() { +/* +Description: Clean the file. +Input params: (fileName string) +*/ +func CleanFile() { err := gouse.CleanFile("data.json") if err != nil { println(err.Error()) @@ -131,7 +169,11 @@ func IoCleanFile() { println("file cleaned") } -func IoCopyFile() { +/* +Description: Copy content from one file to another. +Input params: (sourceName string, destinationName string) +*/ +func CopyFile() { err := gouse.CopyFile("data.json", "data2.json") if err != nil { println(err.Error()) @@ -139,7 +181,11 @@ func IoCopyFile() { println("file copied") } -func IoCreateFile() { +/* +Description: Create a file. +Input params: (fileName string) +*/ +func CreateFile() { err := gouse.CreateFile("data.json") if err != nil { println(err.Error()) @@ -147,7 +193,11 @@ func IoCreateFile() { println("file created") } -func IoFileInfo() { +/* +Description: Get file info. +Input params: (fileName string) +*/ +func FileInfo() { data, err := gouse.FileInfo("main.go") if err != nil { println(err.Error()) @@ -161,7 +211,11 @@ func IoFileInfo() { fmt.Printf("File info (with system process): %+v\n", data.Sys) } -func IoCheckFile() { +/* +Description: Check if the file exists. +Input params: (fileName string) +*/ +func CheckFile() { isExist, err := gouse.IsExistFile("data.json") if err != nil { println(err.Error()) @@ -173,7 +227,11 @@ func IoCheckFile() { } } -func IoFileObj() { +/* +Description: Write and update object to the file. +Input params: (fileName string, data interface{}) +*/ +func FileObj() { type User struct { Name string Age int @@ -182,7 +240,7 @@ func IoFileObj() { exampleFile := "data.json" // read file - // data, err := io.ReadFileObj[User](exampleFile) + // data, err := .ReadFileObj[User](exampleFile) // if err != nil { // println(err.Error()) // } @@ -225,7 +283,7 @@ func IoFileObj() { } // write the updated data back to the file - // if err := ioutil.WriteFile(exampleFile, updatedData, 0644); err != nil { + // if err := util.WriteFile(exampleFile, updatedData, 0644); err != nil { // println(err.Error()) // return // } @@ -237,7 +295,11 @@ func IoFileObj() { println("data written") } -func IoReadFileByLine() { +/* +Description: Read file by line. +Input params: (fileName string) +*/ +func ReadFileByLine() { data, err := gouse.ReadFileByLine("main.go") if err != nil { println(err.Error()) @@ -247,7 +309,11 @@ func IoReadFileByLine() { } } -func IoRemoveFile() { +/* +Description: Remove file. +Input params: (fileName string) +*/ +func RemoveFile() { err := gouse.RemoveFile("data.json") if err != nil { println(err.Error()) @@ -255,7 +321,11 @@ func IoRemoveFile() { println("file removed") } -func IoRenameFile() { +/* +Description: Rename file. +Input params: (oldName string, newName string) +*/ +func RenameFile() { err := gouse.RenameFile("data.json", "data2.json") if err != nil { println(err.Error()) @@ -263,7 +333,11 @@ func IoRenameFile() { println("file renamed") } -func IoTruncateFile() { +/* +Description: Truncate data of file. +Input params: (fileName string, size int64) +*/ +func TruncateFile() { err := gouse.TruncateFile("data.json", 10) if err != nil { println(err.Error()) @@ -271,7 +345,11 @@ func IoTruncateFile() { println("file truncated to 10 bytes") } -func IoWriteToFile() { +/* +Description: Write data to file. +Input params: (fileName string, data []string) +*/ +func WriteToFile() { err := gouse.WriteFile("data.json", []string{"this is data 1", "this is data 2"}) if err != nil { println(err.Error()) @@ -279,9 +357,11 @@ func IoWriteToFile() { println("file written") } -/* Utility functions */ - -func IoZip() { +/* +Description: Zip files. +Input params: (zipFileName string, filesToZip []string) +*/ +func Zip() { filesToZip := []string{"file1.txt", "file2.txt"} zipFileName := "archive.zip" err := gouse.Zip(zipFileName, filesToZip) @@ -292,7 +372,11 @@ func IoZip() { println("Files zipped successfully:", zipFileName) } -func IoUnzip() { +/* +Description: Unzip files. +Input params: (zipFileName string, destFolder string) +*/ +func Unzip() { destFolder := "unzipped" zipFileName := "archive.zip" err := gouse.Unzip(zipFileName, destFolder) diff --git a/samples/main/index.go b/samples/main/index.go index 4dc21ab..1f96a97 100644 --- a/samples/main/index.go +++ b/samples/main/index.go @@ -40,8 +40,8 @@ func main() { } func apiSample() { - samples.ApiLoadbalancer() - samples.ApiGracefulShutdown() + samples.Loadbalancer() + samples.GracefulShutdown() } func arraySample() { @@ -125,46 +125,44 @@ func cronSample() { } func cryptoSample() { - samples.CryptoEncode() - samples.CryptoDecode() - samples.CryptoEncryptPassword() - samples.CryptoDecryptPassword() - samples.CryptoEncryptFile() - samples.CryptoDecryptFile() + samples.EncodeData() + samples.DecodeData() + samples.EncryptPassword() + samples.DecryptPassword() + samples.EncryptFile() + samples.DecryptFile() } func dateSample() { - samples.DateTime() + samples.TimeElement() samples.DateISO() samples.DateShort() samples.DateLong() samples.DateUTC() - samples.DateToSecond() - samples.DateToMinute() - samples.DateToHour() - samples.DateSleepSecond() - samples.DateSleepMinute() - samples.DateSleepHour() + samples.ToSecond() + samples.ToMinute() + samples.ToHour() + samples.SleepSecond() + samples.SleepMinute() + samples.SleepHour() - samples.DateClock() + samples.Clock() } func functionSample() { - samples.FuncDelay() - samples.FuncRetry() - samples.FuncRemain() - samples.FuncInterval() - samples.FuncLock() - samples.FuncRunTime() + samples.FunctionDelay() + samples.FunctionRetry() + samples.FunctionRemain() + samples.FunctionInterval() + samples.FunctionLock() + samples.FunctionRunTime() } func helperSample() { - samples.HelperRandomID() - samples.HelperUUID() - - samples.HelperAutoMdDoc() + samples.UUID() + samples.AutoMarkdownDocument() } func logSample() { @@ -175,102 +173,96 @@ func logSample() { } func ioSample() { - samples.IoCheckDir() - samples.IoCreateDir() - samples.IoRemoveDir() - samples.IoLsDir() - samples.IoHierarchyDir() - samples.IoCurrentDir() - - samples.IoCheckFile() - samples.IoCreateFile() - samples.IoRemoveFile() - samples.IoReadFileByLine() - samples.IoFileInfo() - samples.IoRenameFile() - samples.IoCopyFile() - samples.IoTruncateFile() - samples.IoCleanFile() - samples.IoWriteToFile() - samples.IoAppendToFile() - samples.IoFileObj() - - samples.IoCreatePath() - samples.IoReadPath() - samples.IoWritePath() - - samples.IoZip() - samples.IoUnzip() + samples.CheckDir() + samples.CreateDir() + samples.RemoveDir() + samples.LsDir() + samples.HierarchyDir() + samples.CurrentDir() + + samples.CheckFile() + samples.CreateFile() + samples.RemoveFile() + samples.ReadFileByLine() + samples.FileInfo() + samples.RenameFile() + samples.CopyFile() + samples.TruncateFile() + samples.CleanFile() + samples.WriteToFile() + samples.AppendToFile() + samples.FileObj() + + samples.CreatePath() + samples.ReadPath() + samples.WritePath() + + samples.Zip() + samples.Unzip() } func mathSample() { - samples.MathIsPrime() - samples.MathIsEven() - samples.MathIsOdd() - samples.MathIsPerfectSquare() - - samples.MathAbs() - samples.MathFloor() - samples.MathCeil() - samples.MathRound() - samples.MathMin() - samples.MathMax() - samples.MathSum() - samples.MathMean() - samples.MathOperators() - samples.MathPower() - samples.MathFactorial() - samples.MathRoot() - - samples.MathLog() - samples.MathPytago() - samples.MathTrigonometry() - samples.MathTransition() - - samples.MathRect() - samples.MathCircle() - samples.MathTriangle() - samples.MathSquare() - samples.MathCube() - samples.MathSphere() - samples.MathCylinder() - samples.MathCone() - samples.MathTrapezoid() - samples.MathParallelogram() - samples.MathRhombus() - samples.MathEllipse() - samples.MathPolygon() + samples.CheckNumber() + + samples.Abs() + samples.Floor() + samples.Ceil() + samples.Round() + samples.MinMaxMean() + samples.Sum() + samples.Operators() + samples.Power() + samples.Factorial() + samples.Root() + + samples.Log() + samples.Pytago() + samples.Trigonometry() + samples.Transition() + + samples.Rect() + samples.Circle() + samples.Triangle() + samples.Square() + samples.Cube() + samples.Sphere() + samples.Cylinder() + samples.Cone() + samples.Trapezoid() + samples.Parallelogram() + samples.Rhombus() + samples.Ellipse() + samples.Polygon() } func mediaSample() { - samples.MediaCanvas() - samples.MediaPngToJpg() + samples.Canvas() + samples.PngToJpg() } func netSample() { - samples.NetOpen() - samples.NetEncode() - samples.NetDecode() - samples.NetCheck() - samples.NetCheckWithStatusCode() - samples.NetHeader() - samples.NetConnectTime() - samples.NetProxy() - samples.ApiPortScanner() - samples.ApiPortChecker() + samples.OpenURL() + samples.EncodeURL() + samples.DecodeURL() + samples.CheckURL() + samples.CheckWithStatusCode() + samples.HeaderURL() + samples.ConnectTime() + samples.Proxy() + samples.PortScanner() + samples.PortChecker() } func numberSample() { - samples.NumRandom() - samples.NumClamp() - samples.NumInRange() + samples.Clamp() + samples.CheckInRange() } func osSample() { - samples.OsSystem() - samples.OsDisk() - samples.OsCpu() - samples.OsProfile() + samples.System() + samples.Disk() + samples.Cpu() + samples.Profile() } func randomSample() { @@ -288,49 +280,49 @@ func regexSample() { } func stringSample() { - samples.StringCapitalize() - samples.StringCamelCase() - samples.StringSnakeCase() - samples.StringKebabCase() - - samples.StringIsLetter() - samples.StringIsDigit() - samples.StringIncludes() - samples.StringIsLower() - samples.StringIsUpper() - - samples.StringSplit() - samples.StringWords() - samples.StringReverse() - samples.StringLower() - samples.StringUpper() - samples.StringRepeat() - samples.StringTruncate() - samples.StringReplace() - samples.StringTrim() - samples.StringTrimBlank() - samples.StringTrimPrefix() - samples.StringTrimSuffix() - samples.StringJoin() - samples.StringConcat() - samples.StringSubStr() - samples.StringSlice() - samples.StringSplice() - samples.StringStartsWith() - samples.StringEndsWith() - samples.StringEscape() - samples.StringUnescape() - samples.StringPad() - - samples.StringCount() - samples.StringLines() - samples.StringIndex() - samples.StringRandom() - samples.StringAt() - samples.StringCodePointAt() - samples.StringCodePoint() - samples.StringFromCodePointAt() - samples.StringFromCodePoint() + samples.Capitalize() + samples.CamelCase() + samples.SnakeCase() + samples.KebabCase() + + samples.IsLetter() + samples.IsDigit() + samples.Includes() + samples.IsLower() + samples.IsUpper() + + samples.Split() + samples.Words() + samples.Reverse() + samples.Lower() + samples.Upper() + samples.Repeat() + samples.Truncate() + samples.Replace() + samples.Trim() + samples.TrimBlank() + samples.TrimPrefix() + samples.TrimSuffix() + samples.Join() + samples.Concat() + samples.SubStr() + samples.Slice() + samples.Splice() + samples.StartsWith() + samples.EndsWith() + samples.Escape() + samples.Unescape() + samples.Pad() + + samples.Count() + samples.Lines() + samples.Index() + samples.RandomChain() + samples.At() + samples.CodePointAt() + samples.CodePoint() + samples.FromCodePointAt() + samples.FromCodePoint() } func structSample() { diff --git a/samples/math.go b/samples/math.go index 70fad21..a84cea6 100644 --- a/samples/math.go +++ b/samples/math.go @@ -6,213 +6,301 @@ import ( "github.com/thuongtruong109/gouse" ) -/* Samples for math check */ - -func MathIsEven() { +/* +Description: Check number is even, odd, perfect square, prime +Input params: (num int) number +*/ +func CheckNumber() { var num = 10 println("Check even number: ", gouse.IsEven(num)) -} - -func MathIsOdd() { - var num = 10 println("Check odd number: ", gouse.IsOdd(num)) -} - -func MathIsPerfectSquare() { - var num = 10 println("Check perfect square number: ", gouse.IsPerfectSquare(num)) -} - -func MathIsPrime() { - var num = 10 println("Check prime number: ", gouse.IsPrime(num)) } -/* Samples for math fomular */ - -func MathLog() { +/* +Description: Calculate logarithm (base 2, 10) of number (F: float) +Input params: (num, base int) +*/ +func Log() { println("Logarithm of integer number: ", gouse.Log(16, 2)) - println("Logarithm of float number: ", fmt.Sprintf("%f", gouse.LogF(20.0, 2.0))) + println("Logarithm of float number: ", gouse.Sprintf("%f", gouse.LogF(20.0, 2.0))) println("Logarithm of integer number (base 2): ", gouse.Log2(16)) - println("Logarithm of float number (base 2): ", fmt.Sprintf("%f", gouse.Log2F(20.0))) + println("Logarithm of float number (base 2): ", gouse.Sprintf("%f", gouse.Log2F(20.0))) println("Logarithm of integer number (base 10): ", gouse.Log10(100)) - println("Logarithm of float number (base 10): ", fmt.Sprintf("%f", gouse.Log10F(20.0))) + println("Logarithm of float number (base 10): ", gouse.Sprintf("%f", gouse.Log10F(20.0))) } -func MathPytago() { - println("Pytago of number (integer): ", fmt.Sprintf("%f", gouse.Pytago(3, 4))) - println("Pytago of number (float): ", fmt.Sprintf("%f", gouse.PytagoF(3.0, 4.0))) +/* +Description: Calculate Pytago (F: float) +Input params: (num1, num2 int) +*/ +func Pytago() { + gouse.Sprintf("Pytago of number (integer): %f", gouse.Pytago(3, 4)) + gouse.Sprintf("Pytago of number (float): %f", gouse.PytagoF(3.0, 4.0)) } -func MathTransition() { +/* +Description: Calculate transition (speed, distance, time) +Input params: Speed(distance, time float64), Distance(speed, time float64), Time(distance, speed float64) +*/ +func Transition() { var distance, speed, time float64 = 100, 10, 10 - println("Speed: ", fmt.Sprintf("%f", gouse.Speed(distance, time))) - println("Distance: ", fmt.Sprintf("%f", gouse.Distance(speed, time))) - println("Time: ", fmt.Sprintf("%f", gouse.Time(distance, speed))) + gouse.Sprintf("Speed: %f", gouse.Speed(distance, time)) + gouse.Sprintf("Distance: %f", gouse.Distance(speed, time)) + gouse.Sprintf("Time: %f", gouse.Time(distance, speed)) } -func MathTrigonometry() { +/* +Description: Calculate trigonometry (sine, cosine, tangent) (F: float) +Input params: (angle float64) +*/ +func Trigonometry() { println("Sine of integer number: ", gouse.Sin(90)) - println("Sine of float number: ", fmt.Sprintf("%f", gouse.SinF(90.0))) + println("Sine of float number: ", gouse.Sprintf("%f", gouse.SinF(90.0))) println("Cosine of integer number: ", gouse.Cos(90)) - println("Cosine of float number: ", fmt.Sprintf("%f", gouse.CosF(90.0))) + println("Cosine of float number: ", gouse.Sprintf("%f", gouse.CosF(90.0))) println("Tangent of integer number: ", gouse.Tan(90)) - println("Tangent of float number: ", fmt.Sprintf("%f", gouse.TanF(90.0))) -} - -/* Samples for math geometry */ - -func MathCircle() { - println("Area of circle (integer): ", fmt.Sprintf("%f", gouse.AreaCircle(10))) - println("Area of circle (float): ", fmt.Sprintf("%f", gouse.AreaCircleF(10.0))) - println("Perimeter of circle (integer): ", fmt.Sprintf("%f", gouse.PeriCircle(10))) - println("Perimeter of circle (float): ", fmt.Sprintf("%f", gouse.PeriCircleF(10.0))) -} - -func MathCone() { - println("Area of cone (integer): ", fmt.Sprintf("%f", gouse.AreaCone(10, 20))) - println("Area of cone (float): ", fmt.Sprintf("%f", gouse.AreaConeF(10.0, 20.0))) - println("Volume of cone (integer): ", fmt.Sprintf("%f", gouse.VolCone(10, 20))) - println("Volume of cone (float): ", fmt.Sprintf("%f", gouse.VolConeF(10.0, 20.0))) -} - -func MathCube() { + println("Tangent of float number: ", gouse.Sprintf("%f", gouse.TanF(90.0))) +} + +/* +Description: Calculate area, perimeter, volume of circle (F: float) +Input params: (radius float64) +*/ +func Circle() { + gouse.Sprintf("Area of circle (integer): %f", gouse.AreaCircle(10)) + gouse.Sprintf("Area of circle (float): %f", gouse.AreaCircleF(10.0)) + gouse.Sprintf("Perimeter of circle (integer): %f", gouse.PeriCircle(10)) + gouse.Sprintf("Perimeter of circle (float): %f", gouse.PeriCircleF(10.0)) +} + +/* +Description: Calculate area, volume of cone (F: float) +Input params: (radius, height float64) +*/ +func Cone() { + gouse.Sprintf("Area of cone (integer): %f", gouse.AreaCone(10, 20)) + gouse.Sprintf("Area of cone (float): %f", gouse.AreaConeF(10.0, 20.0)) + gouse.Sprintf("Volume of cone (integer): %f", gouse.VolCone(10, 20)) + gouse.Sprintf("Volume of cone (float): %f", gouse.VolConeF(10.0, 20.0)) +} + +/* +Description: Calculate area, perimeter, volume of cube (F: float) +Input params: (side float64) +*/ +func Cube() { println("Area of cube (integer): ", gouse.AreaCube(10)) - println("Area of cube (float): ", fmt.Sprintf("%f", gouse.AreaCubeF(10.0))) + println("Area of cube (float): ", gouse.Sprintf("%f", gouse.AreaCubeF(10.0))) println("Perimeter of cube (integer): ", gouse.PeriCube(10)) - println("Perimeter of cube (float): ", fmt.Sprintf("%f", gouse.PeriCubeF(10.0))) + println("Perimeter of cube (float): ", gouse.Sprintf("%f", gouse.PeriCubeF(10.0))) println("Volume of cube (integer): ", gouse.VolCube(10)) - println("Volume of cube (float): ", fmt.Sprintf("%f", gouse.VolCubeF(10.0))) -} - -func MathCylinder() { - println("Area of cylinder (integer): ", fmt.Sprintf("%f", gouse.AreaCylinder(10, 20))) - println("Area of cylinder (float): ", fmt.Sprintf("%f", gouse.AreaCylinderF(10.0, 20.0))) - println("Volume of cylinder (integer): ", fmt.Sprintf("%f", gouse.VolCylinder(10, 20))) - println("Volume of cylinder (float): ", fmt.Sprintf("%f", gouse.VolCylinderF(10.0, 20.0))) -} - -func MathEllipse() { - println("Area of ellipse (integer): ", fmt.Sprintf("%f", gouse.AreaEllipse(10, 20))) - println("Area of ellipse (float): ", fmt.Sprintf("%f", gouse.AreaEllipseF(10.0, 20.0))) -} - -func MathParallelogram() { + println("Volume of cube (float): ", gouse.Sprintf("%f", gouse.VolCubeF(10.0))) +} + +/* +Description: Calculate area, volume of cylinder (F: float) +Input params: (radius, height float64) +*/ +func Cylinder() { + gouse.Sprintf("Area of cylinder (integer): %f", gouse.AreaCylinder(10, 20)) + gouse.Sprintf("Area of cylinder (float): %f", gouse.AreaCylinderF(10.0, 20.0)) + gouse.Sprintf("Volume of cylinder (integer): %f", gouse.VolCylinder(10, 20)) + gouse.Sprintf("Volume of cylinder (float): %f", gouse.VolCylinderF(10.0, 20.0)) +} + +/* +Description: Calculate area, perimeter, volume of ellipse (F: float) +Input params: (major, minor float64) +*/ +func Ellipse() { + gouse.Sprintf("Area of ellipse (integer): %f", gouse.AreaEllipse(10, 20)) + gouse.Sprintf("Area of ellipse (float): %f", gouse.AreaEllipseF(10.0, 20.0)) +} + +/* +Description: Calculate area, perimeter, volume of parallelogram (F: float) +Input params: (base, height float64) +*/ +func Parallelogram() { println("Area of parallelogram (integer): ", gouse.AreaParallelogram(10, 20)) - println("Area of parallelogram (float): ", fmt.Sprintf("%f", gouse.AreaParallelogramF(10.0, 20.0))) + println("Area of parallelogram (float): ", gouse.Sprintf("%f", gouse.AreaParallelogramF(10.0, 20.0))) } -func MathPolygon() { - println("Area of pentagol by number of sides (integer): ", fmt.Sprintf("%f", gouse.AreaPolygon(10, 6))) +/* +Description: Calculate area of pentagon (F: float) +Input params: (side, apothem float64) +*/ +func Polygon() { + gouse.Sprintf("Area of pentagol by number of sides (integer): %f", gouse.AreaPolygon(10, 6)) } -func MathRect() { +/* +Description: Calculate area, perimeter, volume of rectangle (F: float) +Input params: (length, width float64) +*/ +func Rect() { println("Area of rectangle: ", gouse.AreaRect(10, 20)) println("Perimeter of rectangle (integer): ", gouse.PeriRect(10, 20)) - println("Perimeter of rectangle (float): ", fmt.Sprintf("%f", gouse.PeriRectF(10.0, 20.0))) - println("Diagonal of rectangle (integer): ", fmt.Sprintf("%f", gouse.DiagRect(10, 20))) - println("Diagonal of rectangle (float): ", fmt.Sprintf("%f", gouse.DiagRectF(10.0, 20.0))) + println("Perimeter of rectangle (float): ", gouse.Sprintf("%f", gouse.PeriRectF(10.0, 20.0))) + println("Diagonal of rectangle (integer): ", gouse.Sprintf("%f", gouse.DiagRect(10, 20))) + println("Diagonal of rectangle (float): ", gouse.Sprintf("%f", gouse.DiagRectF(10.0, 20.0))) println("Volume of rectangular (integer): ", gouse.VolRect(10, 20, 30)) - println("Volume of rectangular (float): ", fmt.Sprintf("%f", gouse.VolRectF(10.0, 20.0, 30.0))) + println("Volume of rectangular (float): ", gouse.Sprintf("%f", gouse.VolRectF(10.0, 20.0, 30.0))) } -func MathRhombus() { +/* +Description: Calculate area, perimeter, volume of rhombus (F: float) +Input params: (diagonal1, diagonal2 float64) +*/ +func Rhombus() { println("Area of rhombus (integer): ", gouse.AreaRhombus(10, 20)) - println("Area of rhombus (float): ", fmt.Sprintf("%f", gouse.AreaRhombusF(10.0, 20.0))) + println("Area of rhombus (float): ", gouse.Sprintf("%f", gouse.AreaRhombusF(10.0, 20.0))) } -func MathSphere() { - println("Area of sphere (integer): ", fmt.Sprintf("%f", gouse.AreaSphere(10))) - println("Area of sphere (float): ", fmt.Sprintf("%f", gouse.AreaSphereF(10.0))) - println("Volume of sphere (integer): ", fmt.Sprintf("%f", gouse.VolSphere(10))) - println("Volume of sphere (float): ", fmt.Sprintf("%f", gouse.VolSphereF(10.0))) +/* +Description: Calculate area, volume of sphere (F: float) +Input params: (radius float64) +*/ +func Sphere() { + gouse.Sprintf("Area of sphere (integer): %f", gouse.AreaSphere(10)) + gouse.Sprintf("Area of sphere (float): %f", gouse.AreaSphereF(10.0)) + gouse.Sprintf("Volume of sphere (integer): %f", gouse.VolSphere(10)) + gouse.Sprintf("Volume of sphere (float): %f", gouse.VolSphereF(10.0)) } -func MathSquare() { +/* +Description: Calculate area, perimeter, volume of square (F: float) +Input params: (side float64) +*/ +func Square() { println("Area of square (integer): ", gouse.AreaSquare(10)) - println("Area of square (float): ", fmt.Sprintf("%f", gouse.AreaSquareF(10.0))) + println("Area of square (float): ", gouse.Sprintf("%f", gouse.AreaSquareF(10.0))) println("Perimeter of square (integer): ", gouse.PeriSquare(10)) - println("Perimeter of square (float): ", fmt.Sprintf("%f", gouse.PeriSquareF(10.0))) + println("Perimeter of square (float): ", gouse.Sprintf("%f", gouse.PeriSquareF(10.0))) } -func MathTrapezoid() { - println("Area of trapezoid (integer): ", fmt.Sprintf("%f", gouse.AreaTrapezoid(10, 20, 30))) - println("Area of trapezoid (float): ", fmt.Sprintf("%f", gouse.AreaTrapezoidF(10.0, 20.0, 30.0))) +/* +Description: Calculate area, perimeter, volume of trapezoid (F: float) +Input params: (base1, base2, height float64) +*/ +func Trapezoid() { + gouse.Sprintf("Area of trapezoid (integer): %f", gouse.AreaTrapezoid(10, 20, 30)) + gouse.Sprintf("Area of trapezoid (float): %f", gouse.AreaTrapezoidF(10.0, 20.0, 30.0)) } -func MathTriangle() { +/* +Description: Calculate area, perimeter of triangle (F: float) +Input params: (base, height, side float64) +*/ +func Triangle() { println("Area of triangle (integer): ", gouse.AreaTriangle(10, 20)) - println("Area of triangle (float): ", fmt.Sprintf("%f", gouse.AreaTriangleF(10.0, 20.0))) + println("Area of triangle (float): ", gouse.Sprintf("%f", gouse.AreaTriangleF(10.0, 20.0))) println("Perimeter of triangle (integer): ", gouse.PeriTriangle(10, 20, 30)) - println("Perimeter of triangle (float): ", fmt.Sprintf("%f", gouse.PeriTriangleF(10.0, 20.0, 30.0))) + println("Perimeter of triangle (float): ", gouse.Sprintf("%f", gouse.PeriTriangleF(10.0, 20.0, 30.0))) } -/* Samples for math operators */ - -func MathAbs() { +/* +Description: Calculate absolute number +Input params: (num int) +*/ +func Abs() { var num = -10 println("Absolute number: ", gouse.Abs(num)) } -func MathAdd() { +/* +Description: Add two numbers +Input params: (num1, num2 int) +*/ +func Add() { var num1, num2 = 10, -2 println("Add numbers: ", gouse.Add(num1, num2)) } -func MathCeil() { +/* +Description: Calculate Ceil number +Input params: (num float64) +*/ +func Ceil() { var num = 10.49 println("Ceil number: ", gouse.Ceil(num)) } -func MathOperators() { +/* +Description: Divide two numbers +Input params: (num1, num2 int) +*/ +func Operators() { var num1, num2 = 10, -2 println("Quotient of numbers: ", gouse.Divide(num1, num2)) } -func MathFactorial() { +/* +Description: Calculate factorial number +Input params: (num int) +*/ +func Factorial() { var num = 5 println("Factorial of number: ", gouse.Factorial(num)) } -func MathFloor() { +/* +Description: Calculate Floor number +Input params: (num float64) +*/ +func Floor() { var num = 10.49 println("Floor number: ", gouse.Floor(num)) } -func MathMin() { +/* +Description: Find Min, Max, Mean of numbers +Input params: (struct interface{}, fieldName string, value interface{}) +*/ +func MinMaxMean() { var num1, num2, num3, num4 = 10, 20, 30, -2 println("Min number: ", gouse.Min(num1, num2, num3, num4)) -} - -func MathMax() { - var num1, num2, num3, num4 = 10, 20, 30, -2 println("Max number: ", gouse.Max(num1, num2, num3, num4)) -} - -func MathMean() { - var num1, num2, num3, num4 = 10, 20, 30, -2 println("Average/Mean of numbers: ", gouse.Mean(num1, num2, num3, num4)) } -func MathMulti() { +/* +Description: Multiply multiple numbers +Input params: (num ...int) +*/ +func Multi() { var num1, num2, num3, num4 = 10, 20, 30, -2 println("Multiply of numbers: ", gouse.Multi(num1, num2, num3, num4)) } -func MathPower() { +/* +Description: Calculate power of number (F: float) +Input params: Powe2(num int), Pow(num, power int), PoweF(num, power float64) +*/ +func Power() { println("Power square of number: ", gouse.Pow2(2)) println("Power of integer numbers: ", gouse.Pow(2, 3)) println("Power of float numbers: ", gouse.PowF(2.0, 3.0)) } -func MathRemainder() { +/* +Description: Calculate remainder of two numbers +Input params: (num1, num2 int) +*/ +func Remainder() { var num1, num2 = 10, -2 println("Remainder of numbers: ", gouse.Remainder(num1, num2)) } -func MathRoot() { +/* +Description: Calculate square-root, cube-root, nth-root of number (F: float) +Input params: Sqrt(num int), SqrtF(num float64), Cbrt(num int), CbrtF(num float64), Root(num, power int), RootF(num, power float64) +*/ +func Root() { println("Square-Root of integer number: ", gouse.Sqrt(16)) println("Square-Root of float number: ", fmt.Sprintf("%f", gouse.SqrtF(20.0))) @@ -223,17 +311,29 @@ func MathRoot() { println("Nth-Root of float number: ", fmt.Sprintf("%f", gouse.RootF(20.0, 3.0))) } -func MathRound() { +/* +Description: Calculate round number +Input params: (num float64) +*/ +func Round() { var num1, num2 = 10.49, 10.51 println("Round number: ", gouse.Round(num1), gouse.Round(num2)) } -func MathSub() { +/* +Description: Subtract two numbers +Input params: (num1, num2 int) +*/ +func Sub() { var num1, num2 = 10, -2 println("Subtract of numbers: ", gouse.Sub(num1, num2)) } -func MathSum() { +/* +Description: Sum multiple numbers +Input params: (num ...int) +*/ +func Sum() { var num1, num2, num3, num4 = 10, 20, 30, -2 println("Sum of numbers: ", gouse.Sum(num1, num2, num3, num4)) } diff --git a/samples/media.go b/samples/media.go index b77fbd0..db01cc6 100644 --- a/samples/media.go +++ b/samples/media.go @@ -1,7 +1,6 @@ package samples import ( - "fmt" "image/png" "log" "os" @@ -10,12 +9,16 @@ import ( "github.com/thuongtruong109/gouse" ) -func MediaCanvas() { +/* +Description: Create a canvas with a white background and save it as a PNG file +Input params: (size int, background string) +*/ +func Canvas() { avatar, err := gouse.CreateCanvas(200, "#FFFFFF") if err != nil { log.Fatal(err) } - filename := fmt.Sprintf("mockdata/%d.png", time.Now().Unix()) + filename := gouse.Sprintf("mockdata/%d.png", time.Now().Unix()) file, err := os.Create(filename) if err != nil { log.Fatal(err) @@ -23,12 +26,16 @@ func MediaCanvas() { png.Encode(file, avatar) } -func MediaPngToJpg() { +/* +Description: Convert a PNG image to a JPG image +Input params: (jpgPath string, pngPath string) +*/ +func PngToJpg() { err := gouse.PNGToJPG("mockdata/1720031107.png", "mockdata/output.jpg") if err != nil { - fmt.Println(err) + gouse.Println(err) return } - fmt.Println("Conversion successful") + gouse.Println("Conversion successful") } diff --git a/samples/net.go b/samples/net.go index 1c32ceb..cb907d7 100644 --- a/samples/net.go +++ b/samples/net.go @@ -6,7 +6,11 @@ import ( "github.com/thuongtruong109/gouse" ) -func NetCheck() { +/* +Description: Check if a URL is valid +Input params: (url string) +*/ +func CheckURL() { ok, err := gouse.CheckHref("https://google.com") if err != nil { panic(err) @@ -16,9 +20,9 @@ func NetCheck() { /* Description: Check if a URL is valid -Input params: (url) +Input params: (url string) */ -func NetCheckWithStatusCode() { +func CheckWithStatusCode() { statusCode, err := gouse.CheckHrefStatusCode("https://google.com") if err != nil { panic(err) @@ -28,9 +32,9 @@ func NetCheckWithStatusCode() { /* Description: Calculate the time it takes to connect to a URL -Input params: (url) +Input params: (url string) */ -func NetConnectTime() { +func ConnectTime() { connectTime, err := gouse.HrefConnectTime("https://google.com") if err != nil { panic(err) @@ -41,25 +45,25 @@ func NetConnectTime() { /* Description: Encode a URL -Input params: (url) +Input params: (url string) */ -func NetEncode() { +func EncodeURL() { println("Encode: ", gouse.EncodeHref("https://google.com")) } /* Description: Decode a URL -Input params: (url) +Input params: (url string) */ -func NetDecode() { +func DecodeURL() { println("Decode: ", gouse.DecodeHref("https%3A%2F%2Fgoogle.com")) } /* Description: Get the header of a URL -Input params: (url) +Input params: (url string) */ -func NetHeader() { +func HeaderURL() { header, err := gouse.HrefHeader("https://google.com") if err != nil { panic(err) @@ -70,33 +74,33 @@ func NetHeader() { /* Description: Check if a port is open -Input params: (protocol, hostname, port) +Input params: (protocol, hostname string, port int) */ -func ApiPortChecker() { +func PortChecker() { open := gouse.CheckPort("tcp", "localhost", 1313) fmt.Printf("Port Open: %t\n", open) } /* Description: Scan for open ports on a given host. -Input params: (protocol, hostname, start port, end port) +Input params: (protocol, hostname string, startPort, endPort int) */ -func ApiPortScanner() { +func PortScanner() { gouse.ScanPort("tcp", "127.0.0.1", 3000, 8080) } /* Description: Proxy wrapper to another port -Input params: (port, []string{urls}) +Input params: (port string, urls []string{}) */ -func NetProxy() { +func Proxy() { gouse.Proxy("5000", []string{"http://localhost:3000", "http://localhost:3001"}) } /* Description: Open a URL in the default browser -Input params: (url) +Input params: (url string) */ -func NetOpen() { +func OpenURL() { gouse.OpenHref("https://google.com") } diff --git a/samples/number.go b/samples/number.go index d0a1d04..cf5e158 100644 --- a/samples/number.go +++ b/samples/number.go @@ -2,15 +2,10 @@ package samples import "github.com/thuongtruong109/gouse" -func NumClamp() { +func Clamp() { println("Clamp number: ", gouse.Clamp(5, 1, 10)) } -func NumRandom() { - random := gouse.RandNum(1, 10) - println("Random number [1, 10): ", random) -} - -func NumInRange() { +func CheckInRange() { println("Check number is in range: ", gouse.InRange(5, 1, 10)) } diff --git a/samples/os.go b/samples/os.go index 481a5de..61a2d80 100644 --- a/samples/os.go +++ b/samples/os.go @@ -6,7 +6,10 @@ import ( "github.com/thuongtruong109/gouse" ) -func OsCpu() { +/* +Description: Get CPU information +*/ +func Cpu() { cpuInfo, err := gouse.CPU() if err != nil { fmt.Println("Error: ", err) @@ -20,7 +23,10 @@ func OsCpu() { fmt.Println("Cores: ", cpuInfo.Cores) } -func OsDisk() { +/* +Description: Get Disk information +*/ +func Disk() { diskInfo, err := gouse.Disk() if err != nil { fmt.Println("Error: ", err) @@ -34,7 +40,10 @@ func OsDisk() { fmt.Println("Used Space Percent: ", diskInfo.UsedSpacePercent, "%") } -func OsSystem() { +/* +Description: Get Memory information +*/ +func System() { systemInfo, err := gouse.System() if err != nil { fmt.Println("Error: ", err) @@ -53,7 +62,11 @@ func OsSystem() { fmt.Println("Used Memory Percent: ", systemInfo.UsedMemoryPercent, "%") } -func OsProfile() { +/* +Description: Run Profile +Input params: (cpu.pprof, mem.pprof) +*/ +func Profile() { var cpuprofile, memprofile = "cpu.pprof", "mem.pprof" gouse.Profile(cpuprofile, memprofile) diff --git a/samples/random.go b/samples/random.go index 61b13b4..33040d3 100644 --- a/samples/random.go +++ b/samples/random.go @@ -11,14 +11,14 @@ Description: Return a random number between min and max Input params: (min, max int) */ func RandomNumber() { - fmt.Println(gouse.RandNum(1, 100)) + fmt.Println("Random number [1, 10): ", gouse.RandNum(1, 100)) } /* Description: Return a random id (string) with current timestamp */ func RandomID() { - fmt.Println(gouse.RandID()) + fmt.Println("Generate random ID: ", gouse.RandID()) } /* diff --git a/samples/regex.go b/samples/regex.go index 0a392ca..7731819 100644 --- a/samples/regex.go +++ b/samples/regex.go @@ -6,12 +6,20 @@ import ( "github.com/thuongtruong109/gouse" ) -// Note: regex pattern is not include one of (^, $, /g) - +/* +Description: Check if the input string is match with regex pattern +Input params: (pattern, input string) +--> Note: regex pattern is not include one of (^, $, /g) +*/ func RegexIsMatch() { fmt.Println("Match string with regex: ", gouse.IsMatchReg(`[a-z]+\s[a-z]+`, "hello world")) } +/* +Description: Find the first index and value of the match regex pattern +Input params: (pattern, input string) +--> Note: regex pattern is not include one of (^, $, /g) +*/ func RegexMatchIndex() { paragraph := "I think Ruth's dog is cuter than your dog!" matchIdx := gouse.MatchIndexReg(`[^\w\s']`, paragraph) @@ -22,6 +30,11 @@ func RegexMatchIndex() { } } +/* +Description: Find all index and value of the match regex pattern +Input params: (pattern, input string) +--> Note: regex pattern is not include one of (^, $, /g) +*/ func RegexMatch() { fmt.Println("Match string with regex: ", gouse.MatchReg(`[A-Z]`, "Hello World 123")) } diff --git a/samples/string.go b/samples/string.go index 12ca201..1c787d6 100644 --- a/samples/string.go +++ b/samples/string.go @@ -6,138 +6,228 @@ import ( "github.com/thuongtruong109/gouse" ) -/* Samples for string case */ - -func StringCapitalize() { +/* +Description: Capitalize the first letter of a string. +Input params: (s string) +*/ +func Capitalize() { var str = "hello world" println(gouse.Capitalize(str)) } -func StringCamelCase() { +/* +Description: Convert string to Camel Case. +Input params: (s string) +*/ +func CamelCase() { var str = "convert_any-string TO-camelCase in Go! 123" println("Convert string to Camel Case: ", gouse.CamelCase(str)) } -func StringSnakeCase() { +/* +Description: Convert string to Snake Case. +Input params: (s string) +*/ +func SnakeCase() { var str1 = "hello world" var str2 = "ConvertThisString123" println("Convert string to Snake Case: ", gouse.SnakeCase(str1), gouse.SnakeCase(str2)) } -func StringKebabCase() { +/* +Description: Convert string to Kebab Case. +Input params: (s string) +*/ +func KebabCase() { var str = "hello world" println("Convert string to Kebab Case: ", gouse.KebabCase(str)) } -/* Samples for string check */ - -func StringIsLetter() { +/* +Description: Check is letter character. +Input params: (s string) +*/ +func IsLetter() { var str = "hello world" println("Check is letter character: ", gouse.IsLetter(str[0])) } -func StringIsDigit() { +/* +Description: Check is number character. +Input params: (s string) +*/ +func IsDigit() { var str = "1hello world" println("Check is number character: ", gouse.IsDigit(str[0])) } -func StringIncludes() { +/* +Description: Check is contain substring in string. +Input params: (s string, substr string) +*/ +func Includes() { var str = "hello world, this is world" println("Check substring in string: ", gouse.Includes(str, "world")) } -func StringIsLower() { +/* +Description: Check is lower string. +Input params: (s string) +*/ +func IsLower() { var str = "hELLO WORLD" println("Check is lower string: ", gouse.IsLower(str[0])) } -func StringIsUpper() { +/* +Description: Check is upper string. +Input params: (s string) +*/ +func IsUpper() { var str = "Hello world" println("Check is upper string: ", gouse.IsUpper(str[0])) } -/* Samples for string format */ - -func StringSplit() { +/* +Description: Split string by separator. +Input params: (s string, separator string) +*/ +func Split() { var str = "hello world" fmt.Println("Split string by separator: ", gouse.Split(str, "l")) } -func StringWords() { +/* +Description: Split string by single word +Input params: (s string) +*/ +func Words() { var str = "hello world" println("Split string to array of words: ", gouse.Words(str)) } -func StringReverse() { +/* +Description: Reverse string. +Input params: (s string) +*/ +func Reverse() { var str = "hello world" println("Reverse string: ", gouse.Reverse(str)) } -func StringLower() { +/* +Description: Convert string to lower case. +Input params: (s string) +*/ +func Lower() { var str = "HELLO WORLD" println("Lower string (string): ", gouse.Lowers(str)) println("Lower string (byte): ", gouse.Lower(str[0])) println("Lower first string: ", gouse.LowerFirst(str)) } -func StringUpper() { +/* +Description: Convert string to upper case. +Input params: (s string) +*/ +func Upper() { var str = "hello world" println("Upper string (string): ", gouse.Uppers(str)) println("Upper string (byte): ", gouse.Upper(str[0])) println("Upper first string: ", gouse.UpperFirst(str)) } -func StringRepeat() { +/* +Description: Repeat string n times. +Input params: (struct interface{}, fieldName string, value interface{}) +*/ +func Repeat() { var str = "hello world" println("Repeat string: ", gouse.Repeat(str, 3)) } -func StringTruncate() { +/* +Description: Truncate string to n characters or add suffix. +Input params: (s string, length int, suffix ...string) +*/ +func Truncate() { var str = "hello world" println("Truncate string (default): ", gouse.Truncate(str, 5)) println("Truncate string (custom): ", gouse.Truncate(str, 5, "***")) } -func StringReplace() { +/* +Description: Replace substring in string. +Input params: (s string, old string, new string) +*/ +func Replace() { var str = "hello world, this is world" println("Replace string: ", gouse.Replace(str, "world", "golang")) } -func StringTrim() { +/* +Description: Trim left and right space in string. +Input params: (s string) +*/ +func Trim() { var str = " hello world, this is world " println("Trim string: ", gouse.Trim(str)) println("Trim left string: ", gouse.LTrim(str)) println("Trim right string: ", gouse.RTrim(str)) } -func StringTrimBlank() { +/* +Description: Trim left and right blank in string. +Input params: (s string) +*/ +func TrimBlank() { println("Trim blank string: ", gouse.TrimBlank(" hello world, this is world ")) println("Trim left blank string: ", gouse.TrimBlank(" hello world, this is world \t")) println("Trim right blank string: ", gouse.TrimBlank(" hello world, this is world \n")) } -func StringTrimPrefix() { +/* +Description: Trim left and right prefix in string. +Input params: (s string, prefix string) +*/ +func TrimPrefix() { var str = " hello world, this is world " println("Trim prefix string: ", gouse.TrimPrefix(str, " ")) println("Trim suffix string: ", gouse.TrimSuffix(str, " ")) } -func StringTrimSuffix() { +/* +Description: Trim left and right suffix in string. +Input params: (s string, suffix string) +*/ +func TrimSuffix() { var str = " hello world, this is world " println("Trim suffix string: ", gouse.TrimSuffix(str, " ")) } -func StringJoin() { +/* +Description: Join string array to string. +Input params: (s []string, separator string) +*/ +func Join() { var str = []string{"hello", "world"} println("Join string: ", gouse.Join(str, "-")) } -func StringConcat() { +/* +Description: Concat string. +Input params: (s ...string) +*/ +func Concat() { println("Concat string: ", gouse.Concat("hello", "world")) } -func StringSubStr() { +/* +Description: Get substring from string. +Input params: (s string, start int, end ...int) +*/ +func SubStr() { var str = "hello world, this is world" println("Sub string: ", gouse.SubStr(str, 0, 5)) println("Sub string: ", gouse.SubStr(str, 0, 1)) @@ -145,7 +235,11 @@ func StringSubStr() { println("Sub string (with negative index): ", gouse.SubStr(str, -5, -1)) } -func StringSlice() { +/* +Description: Slice string from start to end. +Input params: (s string, start int, end ...int) +*/ +func Slice() { var str = "hello world, this is world" println("Slice string: ", gouse.Slice(str, 0, 5)) println("Slice string: ", gouse.Slice(str, 0, 1)) @@ -154,53 +248,87 @@ func StringSlice() { println("Slice string (with negative index): ", gouse.Slice(str, -5, -1)) } -func StringSplice() { +/* +Description: Splice string from start to end. +Input params: (s string, start int, end int, replace ...string) +*/ +func Splice() { var str = "helloworld, this is world" println("Splice string (default not replace): ", gouse.Splice(str, 0, 5)) println("Splice string (with replace): ", gouse.Splice(str, 1, 5, "golang")) println("Splice string (with replace multiple): ", gouse.Splice(str, 1, 5, "golang1", "golang2")) } -func StringStartsWith() { +/* +Description: Check is start with substring in string. +Input params: (s string, subStr string) +*/ +func StartsWith() { var str = "hello world, this is world" println("Starts with: ", gouse.StartsWith(str, "hello")) } -func StringEndsWith() { +/* +Description: Check is end with substring in string. +Input params: (s string, subStr string) +*/ +func EndsWith() { var str = "hello world, this is world" println("Ends with: ", gouse.EndsWith(str, "world")) } -func StringEscape() { +/* +Description: Convert string to HTML entities. +Input params: (s string) +*/ +func Escape() { var str = "This is a bold statement & \"quote\" โ€“ ยฉ ยฎ" println("Escape string: ", gouse.Escape(str)) } -func StringUnescape() { +/* +Description: Convert HTML entities to string. +Input params: (s string) +*/ +func Unescape() { var str = "This is a <b>bold</b> statement & "quote" โ€“ ยฉ ยฎ" println("Unescape string: ", gouse.Unescape(str)) } -func StringPad() { +/* +Description: Add padding to string from left or right. +Input params: (s string, length int, padStr string) +*/ +func Pad() { var str = "hello world" println("Pad-left string: ", gouse.PadStart(str, 20, '$')) println("Pad-right string: ", gouse.PadEnd(str, 20, '@')) } -/* Samples for string utility */ - -func StringCount() { +/* +Description: Count words/substr in string. +Input params: (s string, substr ...string) +*/ +func Count() { var str = "hello world wo wo" println("Count words/substr in string (default): ", gouse.Count(str)) println("Count words/substr in string (with char): ", gouse.Count(str, "wo")) } -func StringLines() { +/* +Description: Count lines in string. +Input params: (s string) +*/ +func Lines() { var str = "hello world\nwo wo" println("Count lines of string: ", gouse.Lines(str)) } -func StringIndex() { +/* +Description: Get index of substring in string. +Input params: (s string, substr string) +*/ +func Index() { var str = "hello world, this is world" f1, l1 := gouse.IndexSubStr(str, "l") @@ -217,37 +345,52 @@ func StringIndex() { f4, l4 := gouse.IndexSubStr(str, "oo") if f4 == -1 || l4 == -1 { - fmt.Println("Not found") + gouse.Println("Not found") } if gouse.FIndex(str, "oo") == -1 { - fmt.Println("Not found") + gouse.Println("Not found") } if gouse.LIndex(str, "oo") == -1 { - fmt.Println("Not found") + gouse.Println("Not found") } } -func StringRandom() { +/* +Description: Random chain string. +Input params: (length int) +*/ +func RandomChain() { println("Random chain string: ", gouse.RandStr(10)) - println("Random chain number: ", gouse.RandDigit(6)) } -func StringAt() { +/* +Description: Get character at index in string. +Input params: (s string, index int) +*/ +func At() { var str = "hello world" println("At string: ", gouse.At(str, 1)) println("At string: ", gouse.At(str, -5)) } -func StringCodePointAt() { +/* +Description: Get code point at index in string. +Input params: (s string, index int) +*/ +func CodePointAt() { var str = "hello world" println("Code point at string: ", gouse.CodePointAt(str, 1)) println("Code point at string: ", gouse.CodePointAt(str, -5)) } -func StringCodePoint() { +/* +Description: Get code point of string. +Input params: (s string) +*/ +func CodePoint() { asciiValues := gouse.CodePoint("hello world") print("Code point string: ") @@ -256,11 +399,19 @@ func StringCodePoint() { } } -func StringFromCodePointAt() { +/* +Description: Transform code point to string. +Input params: (codePoint int) +*/ +func FromCodePointAt() { println("From code point at string: ", gouse.FromCodePointAt(9733)) println("From code point at string: ", gouse.FromCodePointAt(9731)) } -func StringFromCodePoint() { +/* +Description: Transform multi code points to string. +Input params: (codePoints ...int) +*/ +func FromCodePoint() { println("From code point string: ", gouse.FromCodePoint(104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100)) } diff --git a/samples/struct.go b/samples/struct.go index 6f397e3..4a0ec6e 100644 --- a/samples/struct.go +++ b/samples/struct.go @@ -6,6 +6,10 @@ import ( "github.com/thuongtruong109/gouse" ) +/* +Description: Add fields to a struct +Input params: (struct, newField interface{}) +*/ func StructAdd() { type Add_Person struct { Name string @@ -25,9 +29,13 @@ func StructAdd() { } result := gouse.AddStruct(person, newFields) - fmt.Printf("Struct after adding fields: %+v\n", result) + gouse.Printf("Struct after adding fields: %+v\n", result) } +/* +Description: Clone a struct +Input params: (struct interface{}) +*/ func StructClone() { type Clone_Person struct { Name string @@ -41,15 +49,19 @@ func StructClone() { Email: "example@gmail.com", } - fmt.Printf("Original: %+v\n", person) + gouse.Printf("Original: %+v\n", person) clone := gouse.CloneStruct(person) updateClone := clone.(Clone_Person) updateClone.Name = "Updated Name" - fmt.Printf("Clone: %+v\n", updateClone) + gouse.Printf("Clone: %+v\n", updateClone) } +/* +Description: Get fields from a struct +Input params: (struct interface{}, fieldName string) +*/ func StructGet() { type Get_Person struct { Name string @@ -64,9 +76,13 @@ func StructGet() { } name := gouse.GetStruct(person, "Name") - fmt.Printf("Name: %s\n", name) + gouse.Printf("Name: %s\n", name) } +/* +Description: Check if a struct has a field +Input params: (struct interface{}, fieldName string) +*/ func StructHas() { type Has_Person struct { Name string @@ -81,12 +97,16 @@ func StructHas() { } has := gouse.HasInStruct(person, "Email") - fmt.Printf("Has: %+v\n", has) + gouse.Printf("Has: %+v\n", has) hasEmpty := gouse.HasEmptyInStruct(person, "Email") - fmt.Printf("Has empty: %+v\n", hasEmpty) + gouse.Printf("Has empty: %+v\n", hasEmpty) } +/* +Description: Merge two structs +Input params: (struct1, struct2 interface{}) +*/ func StructMerge() { type Merge_Person struct { Name string @@ -114,13 +134,17 @@ func StructMerge() { merged := gouse.MergeStruct(person, address) - fmt.Printf("Struct after merged: %+v\n", merged) + gouse.Printf("Struct after merged: %+v\n", merged) fmt.Println("Name:", merged.(map[string]interface{})["Name"]) fmt.Println("City:", merged.(map[string]interface{})["City"]) } +/* +Description: Remove fields from a struct +Input params: (struct interface{}, fieldName string) +*/ func StructRemove() { type Remove_Person struct { Name string @@ -134,9 +158,13 @@ func StructRemove() { Email: "example@gmail.com", } - fmt.Printf("Struct after removed field: %+v\n", gouse.RemoveStruct(person, "Email")) + gouse.Printf("Struct after removed field: %+v\n", gouse.RemoveStruct(person, "Email")) } +/* +Description: Set update a field in a struct +Input params: (struct interface{}, fieldName string, value interface{}) +*/ func StructSet() { type Set_Person struct { Name string @@ -152,5 +180,5 @@ func StructSet() { gouse.SetStruct(person, "Name", "Updated Name") - fmt.Printf("Struct after setting field: %+v\n", person) + gouse.Printf("Struct after setting field: %+v\n", person) } diff --git a/samples/time.go b/samples/time.go new file mode 100644 index 0000000..e8d109c --- /dev/null +++ b/samples/time.go @@ -0,0 +1,82 @@ +package samples + +import ( + "fmt" + + "github.com/thuongtruong109/gouse" +) + +/* +Description: Show all time elements +*/ +func TimeElement() { + println("Second:", gouse.Second()) + println("Minute:", gouse.Minute()) + println("Hour:", gouse.Hour()) + println("Day:", gouse.Day()) + println("Month:", gouse.Month()) + println("Year:", gouse.Year()) + println("Weekday:", gouse.Weekday()) + println("Unix:", gouse.Unix()) + println("UnixNano:", gouse.UnixNano()) + println("UnixMilli:", gouse.UnixMilli()) + println("UnixMicro:", gouse.UnixMicro()) + fmt.Println("UnixMilliToTime:", gouse.UnixMilliToTime(1000000000)) + fmt.Println("UnixMicroToTime:", gouse.UnixMicroToTime(1000000000)) + fmt.Println("UnixNanoToTime:", gouse.UnixNanoToTime(1000000000)) +} + +/* +Description: Convert time to seconds +Input params: (time int64) +*/ +func ToSecond() { + println("ToSecond:", gouse.ToSecond(1)) +} + +/* +Description: Convert time to minutes +Input params: (time int64) +*/ +func ToMinute() { + println("ToMinute:", gouse.ToMinute(1)) +} + +/* +Description: Convert time to hours +Input params: (time int64) +*/ +func ToHour() { + println("ToHour:", gouse.ToHour(1)) +} + +/* +Description: Sleep for seconds +Input params: (interval int64) +*/ +func SleepSecond() { + gouse.SleepSecond(1) +} + +/* +Description: Sleep for minutes +Input params: (interval int64) +*/ +func SleepMinute() { + gouse.SleepMinute(1) +} + +/* +Description: Sleep for hours +Input params: (interval int64) +*/ +func SleepHour() { + gouse.SleepHour(1) +} + +/* +Description: Display clock in terminal +*/ +func Clock() { + gouse.TerminalClock() +} diff --git a/samples/type.go b/samples/type.go index c5e00fa..8f49a40 100644 --- a/samples/type.go +++ b/samples/type.go @@ -6,8 +6,9 @@ import ( "github.com/thuongtruong109/gouse" ) -/* Samples for type conversion */ - +/* +Description: Convert string to other type +*/ func TypeStringConvert() { println("Convert string to int: ", gouse.StringToInt("1")) fmt.Println("Convert string to float: ", gouse.StringToFloat("1.1")) @@ -16,6 +17,9 @@ func TypeStringConvert() { fmt.Println("Convert strings to bytes: ", string(gouse.StringsToBytes([]string{"1", "2", "3"})), "->", gouse.StringsToBytes([]string{"1", "2", "3"})) } +/* +Description: Convert other type to string +*/ func TypeCastToString() { println("Cast int to string: ", gouse.IntToString(1)) fmt.Println("Cast float to string: ", gouse.FloatToString(1.1)) @@ -25,6 +29,9 @@ func TypeCastToString() { println("Cast rune to string: ", gouse.RuneToString('a')) } +/* +Description: Convert struct to string, map +*/ func TypeStructConvert() { type CompanyInfo struct { Company string @@ -42,8 +49,9 @@ func TypeStructConvert() { fmt.Println("Struct to map: ", gouse.StructToMap(companyInfo)) } -/* Samples for type check */ - +/* +Description: Check type of variable +*/ func TypeCheck() { println("Check type is int: ", gouse.IsInt(1)) println("Check type is uint: ", gouse.IsUnInt(-1)) @@ -70,6 +78,10 @@ func TypeCheck() { println("Check type is zero: ", gouse.IsZero(0)) } +/* +Description: Check string is UUID +Input params: (id string) +*/ func TypeCheckUUID() { isValid, err := gouse.IsUUID("123e4567-e89b-12d3-a456-426614174000") if err != nil { @@ -78,19 +90,23 @@ func TypeCheckUUID() { println("Check is valid uuid: ", isValid) } -var emails = []string{ - "okahehe@gmail.com", - "test@example.com", - "short@ex.com", - "toolong@exampledomain.com", - "missingat.sign.com", - "invalid@.domain.com", - "user2@yahoo.com", - "bean@outlook.com", - "ititiu19228@student.hcmiu.edu.vn", -} - +/* +Description: Check string is gmail +Input params: (email string) +*/ func TypeCheckGmail() { + var emails = []string{ + "okahehe@gmail.com", + "test@example.com", + "short@ex.com", + "toolong@exampledomain.com", + "missingat.sign.com", + "invalid@.domain.com", + "user2@yahoo.com", + "bean@outlook.com", + "ititiu19228@student.hcmiu.edu.vn", + } + println("--- Check valid gmail ---") for _, email := range emails { isEmail, err := gouse.IsGmail(email) @@ -104,7 +120,23 @@ func TypeCheckGmail() { } } +/* +Description: Check string is yahoo +Input params: (email string) +*/ func TypeCheckYahoo() { + var emails = []string{ + "okahehe@gmail.com", + "test@example.com", + "short@ex.com", + "toolong@exampledomain.com", + "missingat.sign.com", + "invalid@.domain.com", + "user2@yahoo.com", + "bean@outlook.com", + "ititiu19228@student.hcmiu.edu.vn", + } + println("--- Check valid yahoo ---") for _, email := range emails { isEmail, err := gouse.IsYahoo(email) @@ -118,7 +150,23 @@ func TypeCheckYahoo() { } } +/* +Description: Check string is outlook +Input params: (email string) +*/ func TypeCheckOutlook() { + var emails = []string{ + "okahehe@gmail.com", + "test@example.com", + "short@ex.com", + "toolong@exampledomain.com", + "missingat.sign.com", + "invalid@.domain.com", + "user2@yahoo.com", + "bean@outlook.com", + "ititiu19228@student.hcmiu.edu.vn", + } + println("--- Check valid outlook ---") for _, email := range emails { isEmail, err := gouse.IsOutlook(email) @@ -132,7 +180,23 @@ func TypeCheckOutlook() { } } +/* +Description: Check string is education email +Input params: (email string) +*/ func TypeCheckEdu() { + var emails = []string{ + "okahehe@gmail.com", + "test@example.com", + "short@ex.com", + "toolong@exampledomain.com", + "missingat.sign.com", + "invalid@.domain.com", + "user2@yahoo.com", + "bean@outlook.com", + "ititiu19228@student.hcmiu.edu.vn", + } + println("--- Check valid education mail ---") for _, email := range emails { isEmail, err := gouse.IsEdu(email) @@ -146,7 +210,23 @@ func TypeCheckEdu() { } } +/* +Description: Check string is email with custom domain +Input params: (email string, domain string) +*/ func TypeCheckEmail() { + var emails = []string{ + "okahehe@gmail.com", + "test@example.com", + "short@ex.com", + "toolong@exampledomain.com", + "missingat.sign.com", + "invalid@.domain.com", + "user2@yahoo.com", + "bean@outlook.com", + "ititiu19228@student.hcmiu.edu.vn", + } + println("--- Check valid custom domain ---") for _, email := range emails { isEmail, err := gouse.IsEmail(email, "edu.vn") @@ -160,6 +240,10 @@ func TypeCheckEmail() { } } +/* +Description: Check string is valid username recommended +Input params: (username string) +*/ func TypeCheckUsername() { usernames := []string{ "okahehe", @@ -180,6 +264,10 @@ func TypeCheckUsername() { } } +/* +Description: Check string is valid password recommended +Input params: (password string) +*/ func TypeCheckPassword() { passwords := []string{ "okahehe", @@ -201,6 +289,10 @@ func TypeCheckPassword() { } } +/* +Description: Check string is valid phone number +Input params: (phone string) +*/ func TypeCheckPhone() { // Note: Phone format syntax: + () // Reference at https://en.wikipedia.org/wiki/List_of_mobile_telephone_prefixes_by_country#:~:text=Property%20Value%20%20Country%20or%20unrecognized%20territory%20,73%20%20%20Etisalat%20%20%20www.etisalat.af%20 diff --git a/xyz.go b/utility.go similarity index 100% rename from xyz.go rename to utility.go