Skip to content

Commit

Permalink
docs: update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
thuongtruong109 committed Dec 17, 2024
1 parent 7b04731 commit 685fca2
Show file tree
Hide file tree
Showing 26 changed files with 1,092 additions and 507 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto eol=lf
*.go -text diff=golang
File renamed without changes.
12 changes: 10 additions & 2 deletions docs/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ export default defineConfig({
],
},
],
search: {
provider: "local",
options: {
detailedView: true,
},
},

sidebar: {
"/introduction/": {
Expand All @@ -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" },
Expand All @@ -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' },
Expand Down
Binary file modified docs/docs/public/doc_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions samples/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions samples/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand Down
3 changes: 3 additions & 0 deletions samples/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

/*
Description: Read JSON configuration file
Input params: (path string, v interface{})
*/
func ConfigJson() {
type configuration struct {
Expand All @@ -27,6 +28,7 @@ func ConfigJson() {

/*
Description: Read TOML configuration file
Input params: (path string, v interface{})
*/
func ConfigToml() {
type configuration struct {
Expand All @@ -52,6 +54,7 @@ func ConfigToml() {

/*
Description: Read YAML configuration file
Input params: (path string, v interface{})
*/
func ConfigYaml() {
type configuration struct {
Expand Down
23 changes: 22 additions & 1 deletion samples/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,30 @@ 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")

// first param is default command, second param is windows command (default is empty)
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")
Expand All @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions samples/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
62 changes: 13 additions & 49 deletions samples/date.go
Original file line number Diff line number Diff line change
@@ -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())
Expand All @@ -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()
}
Loading

0 comments on commit 685fca2

Please sign in to comment.