Skip to content

Commit 3776b36

Browse files
authored
made fixes to printer and release 1.2.0
Merge pull request #2 from antsankov/printer-fixes
2 parents 7b0c249 + d6b6b09 commit 3776b36

File tree

8 files changed

+41
-61
lines changed

8 files changed

+41
-61
lines changed

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
FROM golang:1.15 as builder
1+
FROM golang:1.21 as builder
32

43
WORKDIR /go/src/antsankov/go-live
54

@@ -13,13 +12,13 @@ RUN CGO_ENABLED=0 make build
1312

1413
# Choose alpine as a base image to make this useful for CI, as many
1514
# CI tools expect an interactive shell inside the container
16-
FROM alpine:3.12 as production
15+
FROM alpine:3.18 as production
1716

1817
COPY --from=builder /go/src/antsankov/go-live/bin/go-live /usr/bin/go-live
1918
RUN chmod +x /usr/bin/go-live
2019

2120
ARG VERSION=none
22-
LABEL version=1.1.0
21+
LABEL version=1.2.0
2322

2423
WORKDIR /workdir
2524

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ cross-compile:
1818
env GOOS=linux GOARCH=amd64 go build -o ./release/go-live-linux-x64 -ldflags "-s -w" -trimpath -mod=readonly
1919
env GOOS=windows GOARCH=386 go build -o ./release/go-live-windows-x32.exe -ldflags "-s -w" -trimpath -mod=readonly
2020
env GOOS=windows GOARCH=amd64 go build -o ./release/go-live-windows-x64.exe -ldflags "-s -w" -trimpath -mod=readonly
21+
env GOOS=darwin GOARCH=arm64 go build -o ./release/go-live-mac-arm64 -ldflags "-s -w" -trimpath -mod=readonly
2122

2223
m1:
2324
env GOOS=darwin GOARCH=arm64 go build -o ./release/go-live-mac-arm64 -ldflags "-s -w" -trimpath -mod=readonly
2425

2526
test:
26-
go test ./... -coverprofile=coverage.out -version=true
27+
go test ./... -coverprofile=coverage.out
2728
go tool cover -html=coverage.out
2829

2930
clean:

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# go-live
44
[![Go Report](https://goreportcard.com/badge/github.com/antsankov/go-live)](https://goreportcard.com/report/github.com/antsankov/go-live)
5-
[![GoDoc](https://godoc.org/github.com/antsankov/go-live?status.svg)](https://pkg.go.dev/github.com/antsankov/go-live@v1.1.0?tab=overview)
5+
[![GoDoc](https://godoc.org/github.com/antsankov/go-live?status.svg)](https://pkg.go.dev/github.com/antsankov/go-live@v1.2.0?tab=overview)
66
[![Snap Package](https://snapcraft.io/go-live/badge.svg)](https://snapcraft.io/go-live)
77

88

@@ -35,26 +35,26 @@ Based on JavaScript's famous `live-server` utility. Supports Linux, Windows, and
3535

3636
### MacOS x64 (without Brew)
3737

38-
`curl -LJO https://github.com/antsankov/go-live/releases/download/v1.1.0/go-live-mac-x64.zip && unzip go-live-mac-x64.zip && mv go-live /usr/local/bin/go-live && chmod +x /usr/local/bin/go-live && go-live`
38+
`curl -LJO https://github.com/antsankov/go-live/releases/download/v1.2.0/go-live-mac-x64.zip && unzip go-live-mac-x64.zip && mv go-live /usr/local/bin/go-live && chmod +x /usr/local/bin/go-live && go-live`
3939

4040
### MacOS Apple Silicon (without Brew)
4141

42-
`curl -LJO https://github.com/antsankov/go-live/releases/download/v1.1.0/go-live-mac-arm64.zip && unzip go-live-mac-arm64.zip && mv go-live /usr/local/bin/go-live && chmod +x /usr/local/bin/go-live && go-live`
42+
`curl -LJO https://github.com/antsankov/go-live/releases/download/v1.2.0/go-live-mac-arm64.zip && unzip go-live-mac-arm64.zip && mv go-live /usr/local/bin/go-live && chmod +x /usr/local/bin/go-live && go-live`
4343

4444
### Linux (using Snapcraft)
4545
`snap install go-live`
4646

4747
### Linux x32 (Ubuntu/RHEL/etc.):
48-
`wget https://github.com/antsankov/go-live/releases/download/v1.1.0/go-live-linux-x32 -O /usr/bin/go-live && chmod +x /usr/bin/go-live`
48+
`wget https://github.com/antsankov/go-live/releases/download/v1.2.0/go-live-linux-x32 -O /usr/bin/go-live && chmod +x /usr/bin/go-live`
4949

5050
### Linux x64 (Ubuntu/RHEL/etc.):
51-
`wget https://github.com/antsankov/go-live/releases/download/v1.1.0/go-live-linux-x64 -O /usr/bin/go-live && chmod +x /usr/bin/go-live`
51+
`wget https://github.com/antsankov/go-live/releases/download/v1.2.0/go-live-linux-x64 -O /usr/bin/go-live && chmod +x /usr/bin/go-live`
5252

5353
### Linux ARM32 (Ubuntu/RHEL/etc.):
54-
`wget https://github.com/antsankov/go-live/releases/download/v1.1.0/go-live-linux-arm32 -O /usr/bin/go-live && chmod +x /usr/bin/go-live`
54+
`wget https://github.com/antsankov/go-live/releases/download/v1.2.0/go-live-linux-arm32 -O /usr/bin/go-live && chmod +x /usr/bin/go-live`
5555

5656
### Linux ARM64 (Ubuntu/RHEL/etc.):
57-
`wget https://github.com/antsankov/go-live/releases/download/v1.1.0/go-live-linux-arm64 -O /usr/bin/go-live && chmod +x /usr/bin/go-live`
57+
`wget https://github.com/antsankov/go-live/releases/download/v1.2.0/go-live-linux-arm64 -O /usr/bin/go-live && chmod +x /usr/bin/go-live`
5858

5959
### Docker
6060
`docker pull antsankov/go-live`
@@ -65,7 +65,7 @@ To run (will serve current directory on port 9000):
6565

6666
### Windows
6767

68-
[Download Here and Execute](https://github.com/antsankov/go-live/releases/tag/v1.1.0)
68+
[Download Here and Execute](https://github.com/antsankov/go-live/releases/tag/v1.2.0)
6969

7070
- Chocolatey coming soon! (Help wanted)
7171
- Make sure when running that all necessary ports are open and user has permissions (Help wanted)
@@ -92,7 +92,7 @@ make cross-compile && ls release/
9292
- You need to have a valid developer certficate - check `security find-identity -p codesigning`. If it is not valid, see https://developer.apple.com/forums/thread/86161 -- you need to check the info of the developer cert to see if the "Organizational Unit" certificate is installed.
9393
- For gon to work, you need to use the hacked version https://github.com/mitchellh/gon/issues/64#issuecomment-1336311570 to release on Apple Silicon
9494
- The "ac-password" in gon is an App specfic password for your Apple ID.
95-
- For docker (remember for version and for latest): `sudo docker build -t antsankov/go-live:v1.1.0 .` and `sudo docker push antsankov/go-live:v1.1.0`
95+
- For docker (remember for version and for latest): `sudo docker build -t antsankov/go-live:v1.2.0 .` and `sudo docker push antsankov/go-live:v1.2.0`
9696
## Flags
9797
```
9898
-h Print help message for go-live

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/antsankov/go-live
22

3-
go 1.15
3+
go 1.21
44

55
require github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4

lib/lib_test.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,6 @@ func TestServerWithoutCache(t *testing.T) {
3333
}
3434
}
3535

36-
// func TestServerWithCache(t *testing.T) {
37-
// go StartServer(".", ":91", false)
38-
// resp, err := http.Get("http://127.0.0.1:80/")
39-
// if err != nil {
40-
// t.Errorf("Couldn't get for the test %s", err)
41-
// }
42-
43-
// body, _ := ioutil.ReadAll(resp.Body)
44-
// if resp.Header.Get("Cache-Control") == "" {
45-
// t.Error("Server not setting cache control")
46-
// }
47-
// if resp.StatusCode != 200 {
48-
// t.Error("Server not returning 200")
49-
// }
50-
// if body == nil {
51-
// t.Error("Body is nil, server not working")
52-
// }
53-
// }
54-
5536
func TestInitialPrint(t *testing.T) {
5637
rescueStdout := os.Stdout
5738
r, w, _ := os.Pipe()
@@ -81,7 +62,7 @@ func TestPrintServerInfo(t *testing.T) {
8162
r, w, _ := os.Pipe()
8263
os.Stdout = w
8364

84-
printServerInformation("/", ":80", "127.0.0.1")
65+
printServerInformation("/", ":80")
8566

8667
w.Close()
8768
out, _ := ioutil.ReadAll(r)

lib/printer.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,29 @@ import (
66
"time"
77
)
88

9+
// VERSION of Package
10+
const VERSION = "1.2.0"
11+
912
func printStartMessage(path string, port string) {
13+
// Clear the screen.
1014
fmt.Print("\033[2J")
15+
// Move the cursor to the upper-left corner of the screen.
1116
fmt.Print("\033[H")
12-
fmt.Println("go-live\n--")
17+
fmt.Printf("go-live\n--\n")
1318
fmt.Printf("Serving: %s\n", path)
1419
fmt.Printf("Local: http://localhost%s/\n", port)
1520
}
1621

17-
func printServerInformation(path string, port string, lastIP string) {
18-
// Move to the fifth row, change if more print statements are added.
22+
func printServerInformation(path string, port string) {
23+
// Move to the fifth row, 1st column change if more print statements are added.
1924
fmt.Print("\033[5;1H")
2025
localIP, err := GetLocalIP()
21-
if err == nil {
26+
if err == nil && localIP != "" {
2227
fmt.Printf("Net: http://%s%s/\n", localIP, port)
23-
if lastIP == "" {
24-
lastIP = localIP
25-
}
2628
} else {
27-
// This is case when connection disconnects
28-
if lastIP != localIP {
29-
printStartMessage(path, port)
30-
fmt.Print("\033[6;1H")
31-
lastIP = localIP
32-
} else {
33-
lastIP = ""
34-
fmt.Println()
35-
}
29+
// If there is no network connection, erase the line.
30+
fmt.Print("\033[K")
31+
fmt.Println()
3632
}
3733
fmt.Println("\nRequests:", requests)
3834
}
@@ -50,10 +46,12 @@ func Printer(dir string, port string) {
5046
}
5147

5248
printStartMessage(path, port)
53-
var lastIP string
5449
for {
55-
printServerInformation(path, port, lastIP)
56-
fmt.Println(time.Since(start).Round(time.Second))
57-
time.Sleep(250 * time.Millisecond)
50+
time.Sleep(100 * time.Millisecond)
51+
printServerInformation(path, port)
52+
// Move to the timeSince row, and clear it.
53+
fmt.Print("\033[8;1H")
54+
fmt.Print("\033[K")
55+
fmt.Printf("%s\n", time.Since(start).Round(time.Second))
5856
}
5957
}

main.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import (
44
"flag"
55
"fmt"
66
"os"
7+
"runtime"
78

89
"github.com/antsankov/go-live/lib"
910
"github.com/pkg/browser"
1011
)
1112

1213
// VERSION of Package
13-
const VERSION = "1.1.0"
14+
const VERSION = "1.2.0"
1415

1516
func main() {
1617
var _quiet bool
@@ -34,8 +35,8 @@ func main() {
3435

3536
flag.Parse()
3637

37-
if _version {
38-
fmt.Println(VERSION)
38+
if _version || (len(os.Args) >= 2 && os.Args[1] == "version") {
39+
fmt.Printf("v%s (%s/%s)\n", VERSION, runtime.GOOS, runtime.GOARCH)
3940
return
4041
}
4142

@@ -56,7 +57,7 @@ func main() {
5657
err = lib.StartServer(_dir, ":80", true)
5758
} else {
5859
// If user is sudo we don't launch the browser.
59-
if _quiet == false && isSudo() == false {
60+
if !_quiet && !isSudo() {
6061
browser.OpenURL(fmt.Sprintf("http://localhost%s", _port))
6162
}
6263
err = lib.StartServer(_dir, _port, _cache)

snap/snapcraft.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: go-live
2-
version: '1.1.0'
2+
version: '1.2.0'
33
summary: A very lightweight CLI utility to start serving a file directory
44
description: |
55
go-live can be used for local web development, production static-site serving, or as a network file server. By default go-live serves the directory it is executed in.
@@ -27,6 +27,6 @@ apps:
2727
parts:
2828
go-live:
2929
plugin: go
30-
go-channel: 1.21/candidate
30+
go-channel: 1.21/stable
3131
source: .
3232
source-type: git

0 commit comments

Comments
 (0)