Skip to content

Commit 35ab30c

Browse files
authored
Manage all dependencies itself
1 parent 7986fce commit 35ab30c

File tree

37 files changed

+918
-27
lines changed

37 files changed

+918
-27
lines changed

cmd/daze/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
"time"
1616

1717
"github.com/libraries/daze"
18+
"github.com/libraries/daze/lib/doa"
19+
"github.com/libraries/daze/lib/gracefulexit"
20+
"github.com/libraries/daze/lib/rate"
1821
"github.com/libraries/daze/protocol/ashe"
1922
"github.com/libraries/daze/protocol/baboon"
2023
"github.com/libraries/daze/protocol/czar"
2124
"github.com/libraries/daze/protocol/dahlia"
22-
"github.com/libraries/go/doa"
23-
"github.com/libraries/go/gracefulexit"
24-
"github.com/libraries/go/rate"
2525
)
2626

2727
// Conf is acting as package level configuration.

daze.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import (
2727
"sync"
2828
"time"
2929

30-
"github.com/libraries/go/doa"
31-
"github.com/libraries/go/lru"
32-
"github.com/libraries/go/pretty"
33-
"github.com/libraries/go/rate"
30+
"github.com/libraries/daze/lib/doa"
31+
"github.com/libraries/daze/lib/lru"
32+
"github.com/libraries/daze/lib/pretty"
33+
"github.com/libraries/daze/lib/rate"
3434
)
3535

3636
// ============================================================================
@@ -1209,7 +1209,7 @@ func LoadApnic() map[string][]*net.IPNet {
12091209
log.Println("main: load apnic data from", url)
12101210
rep := doa.Try(http.Get(url))
12111211
defer rep.Body.Close()
1212-
f := io.TeeReader(rep.Body, pretty.NewProgressWriter(rep.ContentLength))
1212+
f := io.TeeReader(rep.Body, pretty.NewProgressWriter(uint64(rep.ContentLength)))
12131213
r := map[string][]*net.IPNet{}
12141214
s := bufio.NewScanner(f)
12151215
for s.Scan() {

daze_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os/exec"
77
"testing"
88

9-
"github.com/libraries/go/doa"
9+
"github.com/libraries/daze/lib/doa"
1010
)
1111

1212
const (

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
module github.com/libraries/daze
22

33
go 1.25.0
4-
5-
require github.com/libraries/go v1.0.5

lib/doa/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Doa
2+
3+
Package doa is the abbreviation of the "Dead or alive". It provides some easy ways to make you panic down the program.
4+
5+
> One of the benefits of detecting problems as soon as you can is that you can crash earlier, and crashing is often the bet thing you can do. The alternative may be to continue, writing corrupted data to some vital database or commanding the washing machine into its twentieth consecutive spin cycle.
6+
7+
Crash is not poison, it's "Quit gracefully".

lib/doa/doa.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Package doa stands for "dead or alive". It provides simple utilities to intentionally crash the program with a panic.
2+
package doa
3+
4+
import (
5+
"log"
6+
)
7+
8+
// Doa checks a boolean condition and triggers a panic if it’s false.
9+
func Doa(b bool) {
10+
if !b {
11+
log.Panicln("doa: unreachable")
12+
}
13+
}
14+
15+
// Err returns the error passed to it, ignoring the first argument.
16+
func Err(a any, err error) error {
17+
return err
18+
}
19+
20+
// Nil checks if an error is non-nil and panics if it is.
21+
func Nil(err error) {
22+
if err != nil {
23+
log.Panicln("doa:", err)
24+
}
25+
}
26+
27+
// Try returns a value if there’s no error, otherwise it panics.
28+
func Try[T any](a T, err error) T {
29+
if err != nil {
30+
log.Panicln("doa:", err)
31+
}
32+
return a
33+
}
34+
35+
// Val returns the first argument, ignoring the error.
36+
func Val[T any](a T, err error) T {
37+
return a
38+
}

lib/gracefulexit/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Gracefulexit
2+
3+
Package gracefulexit provides a method to exit the program gracefully. A graceful exit (or graceful handling) is a simple programming idiom[citation needed] wherein a program detects a serious error condition and "exits gracefully" in a controlled manner as a result. Often the program prints a descriptive error message to a terminal or log as part of the graceful exit.

lib/gracefulexit/cmd/http/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net"
6+
"net/http"
7+
8+
"github.com/libraries/daze/lib/gracefulexit"
9+
)
10+
11+
func main() {
12+
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
13+
w.Write([]byte("Hello World!"))
14+
w.Write([]byte("\n"))
15+
})
16+
log.Println("main: listen and server on 127.0.0.1:8080")
17+
l, err := net.Listen("tcp", "127.0.0.1:8080")
18+
if err != nil {
19+
log.Panicln("main:", err)
20+
}
21+
server := http.Server{}
22+
go server.Serve(l)
23+
gracefulexit.Wait()
24+
log.Println("main: server close")
25+
server.Close()
26+
log.Println("main: done")
27+
}

lib/gracefulexit/gracefulexit.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Package gracefulexit provides a method to exit the program gracefully. A graceful exit (or graceful handling) is a
2+
// simple programming idiom[citation needed] wherein a program detects a serious error condition and "exits gracefully"
3+
// in a controlled manner as a result. Often the program prints a descriptive error message to a terminal or log as part
4+
// of the graceful exit.
5+
package gracefulexit
6+
7+
import (
8+
"os"
9+
"os/signal"
10+
)
11+
12+
// Chan create a channel for os.Signal.
13+
func Chan() chan os.Signal {
14+
buffer := make(chan os.Signal, 1)
15+
signal.Notify(buffer, os.Interrupt)
16+
return buffer
17+
}
18+
19+
// Wait for a signal.
20+
func Wait() {
21+
<-Chan()
22+
}

lib/lru/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Lru
2+
3+
Package lru implements an LRU cache.

0 commit comments

Comments
 (0)