-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
288 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: goreleaser | ||
|
||
on: | ||
push: | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
build-ui: | ||
uses: ./.github/workflows/build-ui.yml | ||
|
||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: stable | ||
|
||
- name: Download UI file | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: ui | ||
|
||
- name: Move UI file | ||
run: mv index.html internal/ui/index.html | ||
|
||
- name: Run goreleaser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json | ||
|
||
version: 1 | ||
|
||
before: | ||
hooks: | ||
- go mod tidy | ||
|
||
builds: | ||
- binary: gsa | ||
ldflags: | ||
- "-s -w" | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- darwin | ||
- windows | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
flags: -trimpath | ||
tags: | ||
- embed | ||
|
||
archives: | ||
- format: tar.gz | ||
name_template: >- | ||
{{- .ProjectName }}_ | ||
{{- .Os }}_ | ||
{{- .Arch }} | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
|
||
checksum: | ||
name_template: 'checksums.txt' | ||
|
||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- "^docs:" | ||
- "^test:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package global | ||
|
||
// ShowFileSizes an ugly hack to control the output format of file | ||
// HideDetail an ugly hack to control the output format of file | ||
// Should find a replacement for this | ||
var ShowFileSizes = false | ||
var HideDetail = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package printer | ||
|
||
import ( | ||
"github.com/Zxilly/go-size-analyzer/internal" | ||
"github.com/Zxilly/go-size-analyzer/internal/ui" | ||
"strings" | ||
) | ||
|
||
const ReplacedStr = `"GSA_PACKAGE_DATA"` | ||
|
||
func Html(r *internal.Result) []byte { | ||
json := Json(r, &JsonOption{hideDetail: true}) | ||
return []byte(strings.Replace(ui.GetTemplate(), ReplacedStr, string(json), 1)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
index.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build embed | ||
|
||
package ui | ||
|
||
import ( | ||
_ "embed" | ||
) | ||
|
||
//go:embed index.html | ||
var tmpl string | ||
|
||
func GetTemplate() string { | ||
return tmpl | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build !embed | ||
|
||
package ui | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"log/slog" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
const BaseUrl = "https://github.com/Zxilly/go-size-analyzer/releases/download/ui/index.html" | ||
|
||
func GetTemplate() string { | ||
slog.Info("Downloading template") | ||
resp, err := http.Get(BaseUrl) | ||
if err != nil { | ||
slog.Error(fmt.Sprintf("Error: %v", err)) | ||
os.Exit(1) | ||
} | ||
defer func(Body io.ReadCloser) { | ||
_ = Body.Close() | ||
}(resp.Body) | ||
|
||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
slog.Error(fmt.Sprintf("Error: %v", err)) | ||
os.Exit(1) | ||
} | ||
|
||
return string(body) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package utils | ||
|
||
import ( | ||
"log/slog" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func GetUrlFromListen(listen string) string { | ||
// get port from listen | ||
parts := strings.Split(listen, ":") | ||
if parts == nil || len(parts) < 2 { | ||
slog.Error("invalid listen address", "listen", listen) | ||
os.Exit(1) | ||
} | ||
return "http://localhost:" + parts[1] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package utils | ||
|
||
import ( | ||
"io" | ||
"log/slog" | ||
"os" | ||
"sync" | ||
) | ||
|
||
func InitLogger(level slog.Level) { | ||
slog.SetDefault(slog.New(slog.NewTextHandler(Stdout, &slog.HandlerOptions{ | ||
ReplaceAttr: func(groups []string, a slog.Attr) slog.Attr { | ||
// remove time | ||
if a.Key == "time" { | ||
return slog.Attr{} | ||
} | ||
return a | ||
}, | ||
Level: level, | ||
}))) | ||
} | ||
|
||
type SyncOutput struct { | ||
sync.Mutex | ||
output io.Writer | ||
} | ||
|
||
func (s *SyncOutput) Write(p []byte) (n int, err error) { | ||
s.Lock() | ||
defer s.Unlock() | ||
return s.output.Write(p) | ||
} | ||
|
||
func (s *SyncOutput) SetOutput(output io.Writer) { | ||
s.Lock() | ||
defer s.Unlock() | ||
s.output = output | ||
} | ||
|
||
var Stdout = &SyncOutput{ | ||
Mutex: sync.Mutex{}, | ||
output: os.Stderr, | ||
} | ||
|
||
var _ io.Writer = Stdout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
// WaitSignal waits for a Ctrl+C signal to exit the program. | ||
func WaitSignal() { | ||
done := make(chan os.Signal, 1) | ||
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
fmt.Println("Press Ctrl+C to exit") | ||
<-done | ||
} |
Oops, something went wrong.