Skip to content

Commit

Permalink
fix: cast private function
Browse files Browse the repository at this point in the history
Signed-off-by: Eray Ates <[email protected]>
  • Loading branch information
rytsh committed Sep 10, 2024
1 parent 8f5b6aa commit f1835c5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
.DEFAULT_GOAL := help

.PHONY: example test coverage help html html-gen html-wsl

.PHONY: test-data
test-data: export DATA ?= ColorGroup
test-data: ## Run data test
@go test -timeout 30s -v -run ^Test_Data$

.PHONY: test
test: export DATA ?= ColorGroup
test: ## Run unit tests
@go test -race -cover ./...

.PHONY: coverage
coverage: ## Run unit tests with coverage
@go test -v -race -cover -coverpkg=./... -coverprofile=coverage.out -covermode=atomic ./...
@go tool cover -func=coverage.out

.PHONY: html
html: ## Show html coverage result
@go tool cover -html=./coverage.out

.PHONY: html-gen
html-gen: ## Export html coverage result
@go tool cover -html=./coverage.out -o ./coverage.html

.PHONY: html-wsl
html-wsl: html-gen ## Open html coverage result in wsl
@explorer.exe `wslpath -w ./coverage.html` || true

.PHONY: help
help: ## Display this help screen
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
4 changes: 2 additions & 2 deletions cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"strconv"
)

// ToStringE casts an interface to a string type.
// toStringE casts an interface to a string type.
// Taken from github.com/spf13/cast. All rights reserved.
func ToStringE(i interface{}) (string, error) {
func toStringE(i interface{}) (string, error) {
i = indirectToStringerOrError(i)
switch s := i.(type) {
case string:
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Example() {
Date: types.Time{Time: d},
}

result := (&struct2.Decoder{}).SetTagName("json").Map(group) // default tag name is "struct"
result := new(struct2.Decoder).SetTagName("json").Map(group) // default tag name is "struct"

// fmt.Printf("%#v", result)
SortPrint(result)
Expand Down
2 changes: 1 addition & 1 deletion map.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ FIELDS:
}

if tagOpts.Has("string") {
s, err := ToStringE(val.Interface())
s, err := toStringE(val.Interface())
if err != nil {
continue
}
Expand Down

0 comments on commit f1835c5

Please sign in to comment.