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

replace deprecated ioutil packages #13

Merged
merged 2 commits into from
Dec 3, 2024
Merged
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
17 changes: 9 additions & 8 deletions converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package goreport

import (
"fmt"
"github.com/signintech/gopdf"
"io/ioutil"
"os"
"strconv"
"strings"

"github.com/signintech/gopdf"
)

type Converter struct {
Expand All @@ -18,9 +19,9 @@ type Converter struct {

//var p.ConvPt float64 = 2.834645669

//Read UTF-8 encoding file
// Read UTF-8 encoding file
func (p *Converter) ReadFile(fileName string) error {
buf, err := ioutil.ReadFile(fileName)
buf, err := os.ReadFile(fileName)
if err != nil {
return err
}
Expand Down Expand Up @@ -49,7 +50,7 @@ func (p *Converter) Execute() {
case "TC":
p.TextColor(line, eles)
case "SC":
p.StrokeColor(line, eles)
p.StrokeColor(line, eles)
case "GF", "GS":
p.Grey(line, eles)
case "C", "C1", "CR":
Expand Down Expand Up @@ -149,9 +150,9 @@ func (p *Converter) TextColor(line string, eles []string) {
uint8(AtoiPanic(eles[2], line)), uint8(AtoiPanic(eles[3], line)))
}
func (p *Converter) StrokeColor(line string, eles []string) {
CheckLength(line, eles, 4)
p.Pdf.SetStrokeColor(uint8(AtoiPanic(eles[1], line)),
uint8(AtoiPanic(eles[2], line)), uint8(AtoiPanic(eles[3], line)))
CheckLength(line, eles, 4)
p.Pdf.SetStrokeColor(uint8(AtoiPanic(eles[1], line)),
uint8(AtoiPanic(eles[2], line)), uint8(AtoiPanic(eles[3], line)))
}
func (p *Converter) Oval(line string, eles []string) {
CheckLength(line, eles, 5)
Expand Down
4 changes: 3 additions & 1 deletion example/complex2.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package example

import (
//"fmt"
gr "github.com/mikeshimura/goreport"
"time"
"unicode"

gr "github.com/mikeshimura/goreport"

//"io/ioutil"
"strconv"
"strings"
Expand Down
17 changes: 8 additions & 9 deletions goreport.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package goreport

import (
"bytes"
//"fmt"
"github.com/mikeshimura/dbflute/df"
"io/ioutil"
"os"
"reflect"
"strconv"
"strings"

"github.com/mikeshimura/dbflute/df"
)

const (
Expand Down Expand Up @@ -288,7 +287,7 @@ func (r *GoReport) LineV(x float64, y1 float64, y2 float64) {
r.AddLine("LV\t" + Ftoa(x+adj) + "\t" + Ftoa(r.CurrY+y1) + "\t" + Ftoa(r.CurrY+y2))
}

//SumWork["__lw__"] width adjust
// SumWork["__lw__"] width adjust
func (r *GoReport) Rect(x1 float64, y1 float64, x2 float64, y2 float64) {
r.AddLine("R\t" + Ftoa(x1) + "\t" + Ftoa(r.CurrY+y1) + "\t" + Ftoa(x2) +
"\t" + Ftoa(r.CurrY+y2))
Expand All @@ -302,8 +301,8 @@ func (r *GoReport) TextColor(red int, green int, blue int) {
"\t" + strconv.Itoa(blue))
}
func (r *GoReport) StrokeColor(red int, green int, blue int) {
r.AddLine("SC\t" + strconv.Itoa(red) + "\t" + strconv.Itoa(green) +
"\t" + strconv.Itoa(blue))
r.AddLine("SC\t" + strconv.Itoa(red) + "\t" + strconv.Itoa(green) +
"\t" + strconv.Itoa(blue))
}
func (r *GoReport) GrayFill(grayScale float64) {
r.AddLine("GF\t" + Ftoa(grayScale))
Expand All @@ -320,7 +319,7 @@ func (r *GoReport) Var(name string, val string) {
r.AddLine("V\t" + name + "\t" + val)
}

//unit mm pt in size A4 LTR
// unit mm pt in size A4 LTR
func (r *GoReport) SetPage(size string, unit string, orientation string) {
r.SetConv(unit)
switch size {
Expand Down Expand Up @@ -354,7 +353,7 @@ func (r *GoReport) SetPage(size string, unit string, orientation string) {
r.Convert(false)
}

//unit mm pt in
// unit mm pt in
func (r *GoReport) SetConv(ut string) {
switch ut {
case "mm":
Expand All @@ -379,7 +378,7 @@ func (r *GoReport) SetPageByDimension(unit string, width float64, height float64
}

func (r *GoReport) SaveText(fileName string) {
ioutil.WriteFile(fileName, []byte(r.Converter.Text), os.ModePerm)
os.WriteFile(fileName, []byte(r.Converter.Text), os.ModePerm)
}

type Band interface {
Expand Down
5 changes: 2 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package goreport

import (
//"fmt"
"io/ioutil"
"os"
"strings"
)

Expand Down Expand Up @@ -34,7 +33,7 @@ func addCommaSub(s string) string {
return res
}
func ReadTextFile(filename string, colno int) []interface{} {
res, _ := ioutil.ReadFile(filename)
res, _ := os.ReadFile(filename)
return ReadBytes(res, colno)
}

Expand Down