Skip to content

Commit

Permalink
new: drop gobindata for native embedding (#127)
Browse files Browse the repository at this point in the history
* deps: realign to latest release of wsc and regolithe

* new: drop gobindata for native embed

* fix deprecated use of ioutil

* fix additional depreciation warnings
  • Loading branch information
primalmotion authored Jan 26, 2023
1 parent f7b55ed commit 8a89027
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 323 deletions.
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ lint:
--enable=ineffassign \
--enable=revive \
--enable=unused \
--enable=structcheck \
--enable=staticcheck \
--enable=varcheck \
--enable=deadcode \
--enable=unused \
--enable=unconvert \
--enable=misspell \
--enable=prealloc \
Expand Down
2 changes: 0 additions & 2 deletions cmd/elegen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

package main

//go:generate go-bindata -pkg static -o static/bindata.go templates

import (
"fmt"
"os"
Expand Down
302 changes: 0 additions & 302 deletions cmd/elegen/static/bindata.go

This file was deleted.

7 changes: 5 additions & 2 deletions cmd/elegen/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package main

import (
"embed"
"fmt"
"os"
"path"
Expand All @@ -20,12 +21,14 @@ import (
"strings"
"text/template"

"go.aporeto.io/elemental/cmd/elegen/static"
"go.aporeto.io/regolithe/spec"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

//go:embed templates
var f embed.FS

// An Enum represents an enum.
type Enum struct {
Type string
Expand All @@ -35,7 +38,7 @@ type Enum struct {

func makeTemplate(p string) (*template.Template, error) {

data, err := static.Asset(p)
data, err := f.ReadFile(p)
if err != nil {
return nil, err
}
Expand Down
9 changes: 4 additions & 5 deletions cmd/internal/genopenapi3/converter_errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package genopenapi3
import (
"errors"
"io"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -14,7 +13,7 @@ import (
func TestConverter_Do__error_bad_externalType_mapping(t *testing.T) {
t.Parallel()

specDir, err := ioutil.TempDir("", t.Name()+"_*")
specDir, err := os.MkdirTemp("", t.Name()+"_*")
if err != nil {
t.Fatalf("error creating temporary directory for test function: %v", err)
}
Expand Down Expand Up @@ -55,7 +54,7 @@ func TestConverter_Do__error_bad_externalType_mapping(t *testing.T) {
"test.spec": rawSpec,
} {
filename = filepath.Join(specDir, filename)
if err := ioutil.WriteFile(filename, []byte(content), os.ModePerm); err != nil {
if err := os.WriteFile(filename, []byte(content), os.ModePerm); err != nil {
t.Fatalf("error writing temporary file '%s': %v", filename, err)
}
}
Expand All @@ -73,7 +72,7 @@ func TestConverter_Do__error_bad_externalType_mapping(t *testing.T) {

func TestConverter_Do__error_writer(t *testing.T) {

specDir, err := ioutil.TempDir("", t.Name()+"_*")
specDir, err := os.MkdirTemp("", t.Name()+"_*")
if err != nil {
t.Fatalf("error creating temporary directory for test function: %v", err)
}
Expand Down Expand Up @@ -101,7 +100,7 @@ func TestConverter_Do__error_writer(t *testing.T) {
"test.spec": rawSpec,
} {
filename = filepath.Join(specDir, filename)
if err := ioutil.WriteFile(filename, []byte(content), os.ModePerm); err != nil {
if err := os.WriteFile(filename, []byte(content), os.ModePerm); err != nil {
t.Fatalf("error writing temporary file '%s': %v", filename, err)
}
}
Expand Down
7 changes: 3 additions & 4 deletions cmd/internal/genopenapi3/converter_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -31,7 +30,7 @@ type testCaseRunner struct {
func runAllTestCases(t *testing.T, cases map[string]testCase) {
t.Helper()

rootTmpDir, err := ioutil.TempDir("", t.Name()+"_*")
rootTmpDir, err := os.MkdirTemp("", t.Name()+"_*")
if err != nil {
t.Fatalf("error creating temporary directory for test function: %v", err)
}
Expand Down Expand Up @@ -82,14 +81,14 @@ func (r *testCaseRunner) run(name string, tc testCase) {
}

// this is to ensure that each test case executed within this runner is isolated
specDir, err := ioutil.TempDir(r.rootTmpDir, name)
specDir, err := os.MkdirTemp(r.rootTmpDir, name)
if err != nil {
t.Fatalf("error creating temporary directory for test case: %v", err)
}

for filename, content := range testDataFiles {
filename = filepath.Join(specDir, filename)
if err := ioutil.WriteFile(filename, []byte(content), os.ModePerm); err != nil {
if err := os.WriteFile(filename, []byte(content), os.ModePerm); err != nil {
t.Fatalf("error writing temporary file '%s': %v", filename, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go.aporeto.io/elemental

go 1.13
go 1.16

require go.aporeto.io/regolithe v1.70.0

Expand Down
8 changes: 4 additions & 4 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package elemental
import (
"crypto/tls"
"fmt"
"io/ioutil"
"io"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -155,7 +155,7 @@ func NewRequestFromHTTPRequest(req *http.Request, manager ModelManager) (*Reques
case http.MethodPatch:
operation = OperationPatch
if _, ok := externalSupportedContentType[string(contentType)]; !ok {
data, err = ioutil.ReadAll(req.Body)
data, err = io.ReadAll(req.Body)
if err != nil {
return nil, NewError("Bad Request", fmt.Sprintf("Unable to read body of request: %s", err), "elemental", http.StatusBadRequest)
}
Expand All @@ -165,7 +165,7 @@ func NewRequestFromHTTPRequest(req *http.Request, manager ModelManager) (*Reques
case http.MethodPost:
operation = OperationCreate
if _, ok := externalSupportedContentType[string(contentType)]; !ok {
data, err = ioutil.ReadAll(req.Body)
data, err = io.ReadAll(req.Body)
if err != nil {
return nil, NewError("Bad Request", fmt.Sprintf("Unable to read body of request: %s", err), "elemental", http.StatusBadRequest)
}
Expand All @@ -175,7 +175,7 @@ func NewRequestFromHTTPRequest(req *http.Request, manager ModelManager) (*Reques
case http.MethodPut:
operation = OperationUpdate
if _, ok := externalSupportedContentType[string(contentType)]; !ok {
data, err = ioutil.ReadAll(req.Body)
data, err = io.ReadAll(req.Body)
if err != nil {
return nil, NewError("Bad Request", fmt.Sprintf("Unable to read body of request: %s", err), "elemental", http.StatusBadRequest)
}
Expand Down

0 comments on commit 8a89027

Please sign in to comment.