Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced "io/ioutil" to "io" #40

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.vscode
.env
.env
.DS_Store
test.md
17 changes: 8 additions & 9 deletions pkg/wakabox/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"math"
"os"
"strconv"
Expand Down Expand Up @@ -108,7 +107,7 @@ func (b *Box) UpdateGist(ctx context.Context, id string, gist *github.Gist) erro
}

func (b *Box) UpdateMarkdown(ctx context.Context, title, filename string, content []byte) error {
md, err := ioutil.ReadFile(filename)
md, err := os.ReadFile(filename)
if err != nil {
return fmt.Errorf("wakabox.UpdateMarkdown: Error reade a file: %w", err)
}
Expand All @@ -120,15 +119,14 @@ func (b *Box) UpdateMarkdown(ctx context.Context, title, filename string, conten

newMd := bytes.NewBuffer(nil)
newMd.Write(before)
newMd.WriteString("\n" + title + "\n")
newMd.WriteString("```text\n")
newMd.WriteString("\n```text\n")
newMd.Write(content)
newMd.WriteString("\n")
newMd.WriteString("```\n")
newMd.WriteString("<!-- Powered by https://github.com/YouEclipse/waka-box-go . -->\n")
newMd.WriteString("<!-- Powered by https://github.com/realSunyz/waka-box-go . -->\n")
newMd.Write(after)

err = ioutil.WriteFile(filename, newMd.Bytes(), os.ModeAppend)
err = os.WriteFile(filename, newMd.Bytes(), os.ModeAppend)
if err != nil {
return fmt.Errorf("wakabox.UpdateMarkdown: Error write a file: %w", err)
}
Expand Down Expand Up @@ -177,9 +175,10 @@ func (b *Box) ConstructLine(ctx context.Context, stat wakatime.StatItem) string
// Percent is a float64 from 0-100 representing the progress bar percentage
// Size is an int representing the length of the progress bar in characters
// BarType is a BarType representing the type of barchart: It can be one of the following:
// SOLIDLT SOLIDMD SOLIDDK: Block characters with a dotted background
// UNDERSCORE: Block characters with an line accross the boottom
// EMPTY: Block characters with an empty background
//
// SOLIDLT SOLIDMD SOLIDDK: Block characters with a dotted background
// UNDERSCORE: Block characters with an line accross the boottom
// EMPTY: Block characters with an empty background
func GenerateBarChart(ctx context.Context, percent float64, size int, barType string) string {
// using rune as for utf-8 encoding
syms := BarStyle[barType]
Expand Down
3 changes: 1 addition & 2 deletions pkg/wakabox/box_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package wakabox
import (
"context"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -232,7 +231,7 @@ Other 🕓 32m ▋░░░░░░░░░░░░░░░░░░
if err != nil {
t.Error(err)
}
c, _ := ioutil.ReadFile(filename)
c, _ := os.ReadFile(filename)
if err != nil {
t.Error(err)
}
Expand Down