Replace deprecated io/ioutils (#230)

This commit is contained in:
Manuel Rüger 2023-01-03 18:54:04 +01:00 committed by GitHub
parent f4bbbb19ca
commit 3e558ac2e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 17 additions and 20 deletions

View File

@ -8,5 +8,4 @@ RUN make build
FROM alpine:latest FROM alpine:latest
RUN apk --no-cache add ca-certificates bash git RUN apk --no-cache add ca-certificates bash git
COPY --from=0 /go/src/github.com/kovetskiy/mark/mark /bin/ COPY --from=0 /go/src/github.com/kovetskiy/mark/mark /bin/
RUN mkdir -p /docs
WORKDIR /docs WORKDIR /docs

View File

@ -2,7 +2,7 @@ package main
import ( import (
"errors" "errors"
"io/ioutil" "io"
"net/url" "net/url"
"os" "os"
"strings" "strings"
@ -36,7 +36,7 @@ func GetCredentials(
if password == "" { if password == "" {
password = config.Password password = config.Password
if password == "" { if password == "" {
if ! flags.CompileOnly { if !flags.CompileOnly {
return nil, errors.New( return nil, errors.New(
"Confluence password should be specified using -p " + "Confluence password should be specified using -p " +
"flag or be stored in configuration file", "flag or be stored in configuration file",
@ -47,7 +47,7 @@ func GetCredentials(
} }
if password == "-" { if password == "-" {
stdin, err := ioutil.ReadAll(os.Stdin) stdin, err := io.ReadAll(os.Stdin)
if err != nil { if err != nil {
return nil, karma.Format( return nil, karma.Format(
err, err,

View File

@ -3,7 +3,6 @@ package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
@ -175,7 +174,7 @@ func processFile(
pageID string, pageID string,
username string, username string,
) *confluence.PageInfo { ) *confluence.PageInfo {
markdown, err := ioutil.ReadFile(file) markdown, err := os.ReadFile(file)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"mime/multipart" "mime/multipart"
"net/http" "net/http"
"os" "os"
@ -727,7 +726,7 @@ func newErrorStatusNotOK(request *gopencils.Resource) error {
) )
} }
output, _ := ioutil.ReadAll(request.Raw.Body) output, _ := io.ReadAll(request.Raw.Body)
defer request.Raw.Body.Close() defer request.Raw.Body.Close()
return fmt.Errorf( return fmt.Errorf(

View File

@ -42,7 +42,7 @@ func ResolveAttachments(
return nil, err return nil, err
} }
for i, _ := range attaches { for i := range attaches {
checksum, err := getChecksum(attaches[i].Path) checksum, err := getChecksum(attaches[i].Path)
if err != nil { if err != nil {
return nil, karma.Format( return nil, karma.Format(
@ -147,7 +147,7 @@ func ResolveAttachments(
updating[i] = attach updating[i] = attach
} }
for i, _ := range existing { for i := range existing {
log.Infof(nil, "keeping unmodified attachment: %q", attaches[i].Name) log.Infof(nil, "keeping unmodified attachment: %q", attaches[i].Name)
} }

View File

@ -3,7 +3,7 @@ package includes
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
@ -16,8 +16,9 @@ import (
) )
// <!-- Include: <template path> // <!-- Include: <template path>
// (Delims: (none | "<left>","<right>"))? //
// <optional yaml data> --> // (Delims: (none | "<left>","<right>"))?
// <optional yaml data> -->
var reIncludeDirective = regexp.MustCompile( var reIncludeDirective = regexp.MustCompile(
`(?s)` + `(?s)` +
`<!--\s*Include:\s*(?P<template>.+?)\s*` + `<!--\s*Include:\s*(?P<template>.+?)\s*` +
@ -43,7 +44,7 @@ func LoadTemplate(
var body []byte var body []byte
body, err := ioutil.ReadFile(filepath.Join(base, path)) body, err := os.ReadFile(filepath.Join(base, path))
if err != nil { if err != nil {
err = facts.Format( err = facts.Format(
err, err,

View File

@ -3,7 +3,6 @@ package mark
import ( import (
"bytes" "bytes"
"fmt" "fmt"
"io/ioutil"
"net/url" "net/url"
"os" "os"
"path/filepath" "path/filepath"
@ -80,7 +79,7 @@ func resolveLink(
return "", nil return "", nil
} }
linkContents, err := ioutil.ReadFile(filepath) linkContents, err := os.ReadFile(filepath)
if err != nil { if err != nil {
return "", karma.Format(err, "read file: %s", filepath) return "", karma.Format(err, "read file: %s", filepath)
} }

View File

@ -1,7 +1,7 @@
package mark package mark
import ( import (
"io/ioutil" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
@ -31,11 +31,11 @@ func TestCompileMarkdown(t *testing.T) {
testname := strings.TrimSuffix(basename, ".md") testname := strings.TrimSuffix(basename, ".md")
htmlname := filepath.Join(filepath.Dir(filename), testname+".html") htmlname := filepath.Join(filepath.Dir(filename), testname+".html")
markdown, err := ioutil.ReadFile(filename) markdown, err := os.ReadFile(filename)
if err != nil { if err != nil {
panic(err) panic(err)
} }
html, err := ioutil.ReadFile(htmlname) html, err := os.ReadFile(htmlname)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -52,7 +52,7 @@ func TestCompileMarkdown(t *testing.T) {
func TestExtractDocumentLeadingH1(t *testing.T) { func TestExtractDocumentLeadingH1(t *testing.T) {
filename := "testdata/header.md" filename := "testdata/header.md"
markdown, err := ioutil.ReadFile(filename) markdown, err := os.ReadFile(filename)
if err != nil { if err != nil {
panic(err) panic(err)
} }