Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
shoce committed Oct 27, 2024
1 parent 09c75f1 commit 4d4d54a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 67 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
build-push-ubuntu-24-04:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: version
run: |
BUILD_OS=ubuntu-24.04
echo "BUILD_OS:$BUILD_OS"
echo "BUILD_OS=$BUILD_OS" >> $GITHUB_ENV
VERSION=$( date '+%y%m%d.%H%M.0' )-$BUILD_OS
VERSION=$( date '+%y.%m%d.%H%M' )-$BUILD_OS
echo "VERSION:$VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- uses: actions/setup-go@v4
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
build-push-alpine-3-20:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
# https://github.com/jirutka/setup-alpine
- uses: jirutka/setup-alpine@v1
with:
Expand All @@ -63,7 +63,7 @@ jobs:
BUILD_OS=alpine-3.20
echo "BUILD_OS:$BUILD_OS"
echo "BUILD_OS=$BUILD_OS" >> $GITHUB_ENV
VERSION=$( date '+%y%m%d.%H%M.0' )-$BUILD_OS
VERSION=$( date '+%y.%m%d.%H%M' )-$BUILD_OS
echo "VERSION:$VERSION"
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: go build
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/shoce/hs

go 1.21
go 1.23

require (
github.com/ipfs/go-cid v0.4.1
Expand Down
123 changes: 61 additions & 62 deletions hs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Oct 28 21:37:28 ci sshd[3685911]: error: session_signal_req: session signalling
023/0827 VERBOSE
023/0827 keepalive
go mod init github.com/shoce/hs
go get -a -u -v
go mod tidy
Expand Down Expand Up @@ -116,67 +115,6 @@ var (
TzBiel *time.Location
)

func lognl() {
fmt.Fprintf(os.Stderr, "\n")
}

func underline(s string) string {
if os.Getenv("TERM") != "" {
return "\033[4m" + s + "\033[0m"
}
return s
}

func log(msg string, args ...interface{}) {
var t time.Time
var tsuffix string
var ts string
if LogBeatTime {
const Beat = time.Duration(24) * time.Hour / 1000
t = time.Now().In(TzBiel)
ty := t.Sub(time.Date(t.Year(), 1, 1, 0, 0, 0, 0, TzBiel))
td := t.Sub(time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, TzBiel))
ts = fmt.Sprintf(
"%dy."+"%dd."+"%db.",
t.Year()%1000,
int(ty/(time.Duration(24)*time.Hour))+1,
int(td/Beat),
)
} else {
if LogUTCTime {
t = time.Now().UTC()
tsuffix = "z"
} else {
t = time.Now().Local()
}
ts = fmt.Sprintf(
"%03d."+"%02d%02d."+"%02d"+"%02d."+"%s",
t.Year()%1000, t.Month(), t.Day(),
t.Hour(), t.Minute(), tsuffix,
)
}
if len(args) == 0 {
fmt.Fprint(os.Stderr, ts+" "+msg+NL)
} else {
fmt.Fprintf(os.Stderr, ts+" "+msg+NL, args...)
}
}

func logstatus() {
lognl()
log(underline("Status=%s Hostname=%s Host=%s User=%s hs ; "), Status, Hostname, Host, User)
}

func seps(i int, e int) string {
ee := int(math.Pow(10, float64(e)))
if i < ee {
return fmt.Sprintf("%d", i%ee)
} else {
f := fmt.Sprintf("0%dd", e)
return fmt.Sprintf("%s.%"+f, seps(i/ee, e), i%ee)
}
}

func init() {
TzBiel = time.FixedZone("Biel", 60*60)

Expand Down Expand Up @@ -297,6 +235,67 @@ func main() {
}
}

func lognl() {
fmt.Fprintf(os.Stderr, "\n")
}

func underline(s string) string {
if os.Getenv("TERM") != "" {
return "\033[4m" + s + "\033[0m"
}
return s
}

func log(msg string, args ...interface{}) {
var t time.Time
var tsuffix string
var ts string
if LogBeatTime {
const Beat = time.Duration(24) * time.Hour / 1000
t = time.Now().In(TzBiel)
ty := t.Sub(time.Date(t.Year(), 1, 1, 0, 0, 0, 0, TzBiel))
td := t.Sub(time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, TzBiel))
ts = fmt.Sprintf(
"%dy."+"%dd."+"%db.",
t.Year()%1000,
int(ty/(time.Duration(24)*time.Hour))+1,
int(td/Beat),
)
} else {
if LogUTCTime {
t = time.Now().UTC()
tsuffix = "z"
} else {
t = time.Now().Local()
}
ts = fmt.Sprintf(
"%03d."+"%02d%02d."+"%02d%02d."+"%s",
t.Year()%1000, t.Month(), t.Day(),
t.Hour(), t.Minute(), tsuffix,
)
}
if len(args) == 0 {
fmt.Fprint(os.Stderr, ts+" "+msg+NL)
} else {
fmt.Fprintf(os.Stderr, ts+" "+msg+NL, args...)
}
}

func logstatus() {
lognl()
log(underline("Status=%s Hostname=%s Host=%s User=%s hs ; "), Status, Hostname, Host, User)
}

func seps(i int, e int) string {
ee := int(math.Pow(10, float64(e)))
if i < ee {
return fmt.Sprintf("%d", i%ee)
} else {
f := fmt.Sprintf("0%dd", e)
return fmt.Sprintf("%s.%"+f, seps(i/ee, e), i%ee)
}
}

func copynotify(dst io.Writer, src io.Reader, notify chan error) {
_, err := io.Copy(dst, src)
if notify != nil {
Expand Down

0 comments on commit 4d4d54a

Please sign in to comment.