Skip to content

Commit b901191

Browse files
chore: update sample
1 parent c7271f5 commit b901191

35 files changed

+805
-556
lines changed

api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func (igs *IGracefulShutdown) GracefulShutdown() {
139139

140140
go func() {
141141
defer wg.Done()
142-
time.Sleep(igs.SleepTimout) // 5 * time.Second
142+
time.Sleep(igs.SleepTimout)
143143
}()
144144

145145
c := make(chan os.Signal, 1)
@@ -149,7 +149,7 @@ func (igs *IGracefulShutdown) GracefulShutdown() {
149149

150150
srv := http.Server{
151151
Addr: ":" + igs.Port,
152-
ReadHeaderTimeout: 5 * time.Second, // mitigate Slowloris attack by set timeout
152+
ReadHeaderTimeout: igs.HeaderTimeout,
153153
}
154154

155155
go func() {
@@ -158,7 +158,7 @@ func (igs *IGracefulShutdown) GracefulShutdown() {
158158
go func() {
159159
for {
160160
fmt.Println("waiting for goroutines to finish...")
161-
time.Sleep(igs.HeaderTimeout) // 1 * time.Second
161+
time.Sleep(1 * time.Second)
162162
}
163163
}()
164164
wg.Wait()

cmd/doc_gen.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,15 @@ func highlightName(text string) string {
8383
return fmt.Sprintf("\n# <Badge style='font-size: 1.8rem; text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3); padding: 0.35rem 0.75rem 0.35rem 0;' type='info' text='🔖 %s' />\n", text)
8484
}
8585

86-
func highlightFunction(text string) string {
87-
return fmt.Sprintf("\n### <Badge style='font-size: 1.1rem;' type='tip' text='%s' />\n", text)
88-
}
89-
9086
func generateMarkdownFiles(file os.DirEntry, functions []gouse.Function, path, outputPath, newName string) {
9187
var result []byte
9288

9389
result = append(result, []byte(highlightName(gouse.Capitalize(gouse.TrimSuffix(file.Name(), ".go")))+"\n\n")...)
9490

9591
result = append(result, functions[0].HighlightImport()...)
9692

97-
for i, function := range functions {
98-
result = append(result, highlightFunction(gouse.IntToString(i+1)+". "+gouse.SpaceCase(function.Name))...)
93+
for _, function := range functions {
94+
result = append(result, function.HighlightName()...)
9995
result = append(result, function.HighlightDesc()...)
10096
result = append(result, function.HighlightBody()...)
10197
}

docs/docs/.vitepress/config.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,29 @@ export default defineConfig({
6161
'/receipts/': {
6262
base: '/receipts/',
6363
items: [
64-
{ text: '⚡Api', link: 'api' },
65-
{ text: '📦Array', link: 'array' },
66-
{ text: 'Cache', link: 'cache' },
67-
{ text: '📊Chart', link: 'chart' },
68-
{ text: '🪛Config', link: 'config' },
69-
{ text: '💍Connection', link: 'connection' },
70-
{ text: '🖨️Console', link: 'console' },
71-
{ text: '⌛Cron', link: 'cron' },
72-
{ text: '🔐Crypto', link: 'crypto' },
73-
{ text: '📅Date', link: 'date' },
74-
{ text: '🫛Function', link: 'function' },
75-
{ text: '🎯I/O', link: 'io' },
76-
{ text: '✍️Log', link: 'Log' },
77-
{ text: '➗Math', link: 'math' },
78-
{ text: '📸Media', link: 'media' },
79-
{ text: '🛜Net', link: 'net' },
80-
{ text: '🔢Number', link: 'number' },
81-
{ text: '⭕OS', link: 'os' },
82-
{ text: '💭Random', link: 'random' },
83-
{ text: '🔃Regex', link: 'regex' },
84-
{ text: '🔗String', link: 'string' },
85-
{ text: '🛳️Struct', link: 'struct' },
86-
{ text: '🐧Type', link: 'type' },
64+
{ text: '⚡ Api', link: 'api' },
65+
{ text: '📦 Array', link: 'array' },
66+
{ text: '🎫 Cache', link: 'cache' },
67+
{ text: '📊 Chart', link: 'chart' },
68+
{ text: '🪛 Config', link: 'config' },
69+
{ text: '💍 Connection', link: 'connection' },
70+
{ text: '🖨️ Console', link: 'console' },
71+
{ text: '⌛ Cron', link: 'cron' },
72+
{ text: '🔐 Crypto', link: 'crypto' },
73+
{ text: '📅 Date', link: 'date' },
74+
{ text: '🫛 Function', link: 'function' },
75+
{ text: '🎯 I/O', link: 'io' },
76+
{ text: '✍️ Log', link: 'log' },
77+
{ text: '➗ Math', link: 'math' },
78+
{ text: '📸 Media', link: 'media' },
79+
{ text: '🛜 Net', link: 'net' },
80+
{ text: '🔢 Number', link: 'number' },
81+
{ text: '⭕ OS', link: 'os' },
82+
{ text: '💭 Random', link: 'random' },
83+
{ text: '🔃 Regex', link: 'regex' },
84+
{ text: '🔗 String', link: 'string' },
85+
{ text: '🛳️ Struct', link: 'struct' },
86+
{ text: '🐧 Type', link: 'type' },
8787

8888
// { text: 'Path', link: 'path' },
8989
// { text: 'Security', link: 'security' },

docs/docs/index.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ titleTemplate: Utility presets package
66

77
hero:
88
name: Gouse
9-
text: A modern Golang utility presets
9+
text: Modern utility presets for Golang
1010
tagline: Reuse functions rapidly
1111
actions:
1212
- theme: brand
@@ -40,27 +40,4 @@ features:
4040
<style>
4141
@import './style.css';
4242

43-
:root {
44-
--vp-home-hero-name-color: transparent !important;
45-
--vp-home-hero-name-background: -webkit-linear-gradient(120deg, #bd34fe 30%, #41d1ff) !important;
46-
--vp-home-hero-image-background-image: linear-gradient(-45deg, #bd34fe 50%, #47caff 50%) !important;
47-
--vp-home-hero-image-filter: blur(44px) !important;
48-
}
49-
50-
@media (min-width: 640px) {
51-
:root {
52-
--vp-home-hero-image-filter: blur(56px);
53-
}
54-
}
55-
56-
@media (min-width: 960px) {
57-
:root {
58-
--vp-home-hero-image-filter: blur(68px);
59-
}
60-
}
61-
62-
.VPFooter {
63-
border: none;
64-
}
65-
6643
</style>

docs/docs/introduction/getting-started.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func main() {
2323
## 🦄 Usage
2424

2525
- Using package directly in your module as ultra-lightweight utility functions.
26+
- Import as normal package
2627

2728
```go
2829
package main
@@ -37,4 +38,4 @@ func main() {
3738
}
3839
```
3940

40-
- View more examples at [`receipts`](/receipts/array) page.
41+
- Please refer to the [`receipts`](/receipts/array) for more examples.

docs/docs/introduction/what-is-gouse.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 🧠 Why Gouse?
44

55
- Gouse is a modern essential [`Golang`](https://golang.org/) utility package delivering consistency, modularity, performance, & extras presets inspired by [`Lodash`](https://lodash.com/).
6+
- Built on top of Go language, combined with others open-source packages.
67
- `Javascript` user-friendly syntax.
78
- No config - import as utility functions.
89
- Lightweight package: easy to use, chainable, and extendable, and available in various builds & module formats.
@@ -40,39 +41,39 @@
4041
<tbody>
4142
<td align="left">
4243
<div width="300" height="0"></div><br>
43-
✅ Array <br/>
44-
✅ Api <br/>
45-
✅ Cache <br/>
46-
✅ Chart <br/>
47-
✅ Config <br/>
48-
✅ Console <br/>
49-
✅ Cron <br/>
50-
✅ Crypto <br/>
51-
✅ Date <br/>
44+
<a href="/receipts/array">✅ Array</a> <br/>
45+
<a href="/receipts/api">✅ Api</a> <br/>
46+
<a href="/receipts/cache">✅ Cache</a> <br/>
47+
<a href="/receipts/chart">✅ Chart</a> <br/>
48+
<a href="/receipts/config">✅ Config</a> <br/>
49+
<a href="/receipts/console">✅ Console</a> <br/>
50+
<a href="/receipts/cron">✅ Cron</a> <br/>
51+
<a href="/receipts/crypto">✅ Crypto</a> <br/>
52+
<a href="/receipts/date">✅ Date</a> <br/>
5253
<div width="300" height="0"></div>
5354
</td>
5455
<td align="left">
5556
<div width="300" height="0"></div><br>
56-
✅ Function <br/>
57-
✅ Helper <br/>
58-
✅ I/O <br/>
59-
✅ Connection <br/>
60-
✅ Log <br/>
61-
✅ Math <br/>
62-
✅ Media <br/>
57+
<a href="/receipts/function">✅ Function</a> <br/>
58+
<a href="/receipts/helper">✅ Helper</a> <br/>
59+
<a href="/receipts/io">✅ I/O</a> <br/>
60+
<a href="/receipts/connection">✅ Connection</a> <br/>
61+
<a href="/receipts/log">✅ Log</a> <br/>
62+
<a href="/receipts/math">✅ Math</a> <br/>
63+
<a href="/receipts/media">✅ Media</a> <br/>
6364
<div width="300" height="0"></div>
6465
</td>
6566
<td align="left">
6667
<div width="400" height="0"></div><br>
67-
✅ Net <br/>
68-
✅ Number <br/>
69-
✅ OS <br/>
70-
✅ Random <br/>
71-
✅ Regex <br/>
72-
✅ Struct <br/>
73-
✅ String <br/>
74-
✅ Tool <br/>
75-
✅ Type <br/>
68+
<a href="/receipts/net">✅ Net</a> <br/>
69+
<a href="/receipts/number">✅ Number</a> <br/>
70+
<a href="/receipts/os">✅ OS</a> <br/>
71+
<a href="/receipts/random">✅ Random</a> <br/>
72+
<a href="/receipts/regex">✅ Regex</a> <br/>
73+
<a href="/receipts/struct">✅ Struct</a> <br/>
74+
<a href="/receipts/string">✅ String</a> <br/>
75+
<a href="/receipts/tool">✅ Tool</a> <br/>
76+
<a href="/receipts/type">✅ Type</a> <br/>
7677
<div width="300" height="0"></div>
7778
</td>
7879
</tbody>

docs/docs/receipts/api.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
# <Badge style='font-size: 1.8rem; text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3); padding: 0.35rem 0.75rem 0.35rem 0;' type='info' text='🔖 Api' />
3+
4+
5+
```go
6+
import (
7+
"time" "github.com/thuongtruong109/gouse")
8+
```
9+
10+
## 1. Api loadbalancer
11+
12+
Description: Load balancer with health check<br>Input params: (ILbConfig.ProxyPort, ILbConfig.Backends)<br>
13+
14+
```go
15+
func ApiLoadbalancer() {
16+
lbCfg := gouse.ILbConfig{
17+
ProxyPort: "8080",
18+
Backends: []gouse.IBackend{
19+
{
20+
URL: "http://localhost:8081",
21+
IsDead: false,
22+
},
23+
{
24+
URL: "http://localhost:8082",
25+
IsDead: false,
26+
},
27+
{
28+
URL: "http://localhost:8083",
29+
IsDead: false,
30+
},
31+
},
32+
}
33+
34+
// gouse.HealthCheck() // Enable health check (optional)
35+
gouse.LoadBalancer(lbCfg.ProxyPort, lbCfg.Backends)
36+
}```
37+
38+
## 2. Api graceful shutdown
39+
40+
Description: Graceful shutdown for API server<br>Input params: (IGracefulShutdown)<br>
41+
42+
```go
43+
func ApiGracefulShutdown() {
44+
gs := gouse.IGracefulShutdown{
45+
Port: "3000",
46+
StartMsg: "Starting server at port http://localhost:3000",
47+
ShutdownMsg: "Shutting down server...",
48+
SleepTimout: 5 * time.Second,
49+
HeaderTimeout: 5 * time.Second,
50+
}
51+
52+
gs.GracefulShutdown()
53+
}```

0 commit comments

Comments
 (0)