From aaebbb7b0fa0175cdcc9ff0d6688b4854c4990b5 Mon Sep 17 00:00:00 2001 From: nitram509 Date: Sun, 23 Oct 2022 17:22:11 +0200 Subject: [PATCH 01/10] remove js.Wrapper, because removed with Go 1.18 onwards, see Go 1.18 release notes: https://tip.golang.org/doc/go1.18 --- value.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/value.go b/value.go index 1bc3006..d741997 100644 --- a/value.go +++ b/value.go @@ -27,7 +27,7 @@ func (v Value) JSValue() js.Value { // ValueOf returns the Go value as a new value. func ValueOf(i interface{}) Value { switch i.(type) { - case nil, js.Value, js.Wrapper: + case nil, js.Value: return Value{Value: js.ValueOf(i)} default: v := reflect.ValueOf(i) From c2ce33f5abdc5b84d52202a00aacee68ec7cd54b Mon Sep 17 00:00:00 2001 From: nitram509 Date: Sun, 23 Oct 2022 20:44:10 +0200 Subject: [PATCH 02/10] add convenience method for time.Time conversion --- value.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/value.go b/value.go index d741997..465e0e4 100644 --- a/value.go +++ b/value.go @@ -6,6 +6,7 @@ package vert import ( "reflect" "syscall/js" + "time" ) var ( @@ -47,6 +48,10 @@ func valueOf(v reflect.Value) js.Value { case reflect.Struct: return valueOfStruct(v) default: + if t, ok := v.Interface().(time.Time); ok { + dateConstructor := js.Global().Get("Date") + return dateConstructor.New(t.Format(time.RFC3339)) + } return js.ValueOf(v.Interface()) } } From 722593d0113acaa131983aee29265337f681643b Mon Sep 17 00:00:00 2001 From: nitram509 Date: Sun, 23 Oct 2022 21:13:23 +0200 Subject: [PATCH 03/10] add 1.18 and 1.19 in the test matrix --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f80aaee..e2bc400 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,7 +4,7 @@ jobs: test: strategy: matrix: - go-version: [1.16.x, 1.17.x] + go-version: [1.16.x, 1.17.x, 1.18.x, 1.19.x] os: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.os }} steps: From 84127a31a6c81fe9ea47c330431c4f12b0290c08 Mon Sep 17 00:00:00 2001 From: nitram509 Date: Sun, 23 Oct 2022 21:28:52 +0200 Subject: [PATCH 04/10] fix time.Time detection, because it's a struct --- value.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/value.go b/value.go index 465e0e4..eb40538 100644 --- a/value.go +++ b/value.go @@ -38,6 +38,10 @@ func ValueOf(i interface{}) Value { // valueOf recursively returns a new value. func valueOf(v reflect.Value) js.Value { + if t, ok := v.Interface().(time.Time); ok { + dateConstructor := js.Global().Get("Date") + return dateConstructor.New(t.Format(time.RFC3339)) + } switch v.Kind() { case reflect.Ptr, reflect.Interface: return valueOfPointerOrInterface(v) @@ -48,10 +52,6 @@ func valueOf(v reflect.Value) js.Value { case reflect.Struct: return valueOfStruct(v) default: - if t, ok := v.Interface().(time.Time); ok { - dateConstructor := js.Global().Get("Date") - return dateConstructor.New(t.Format(time.RFC3339)) - } return js.ValueOf(v.Interface()) } } From 8762a19797a700cb8c81e259106d3400cfb18405 Mon Sep 17 00:00:00 2001 From: nitram509 Date: Sun, 23 Oct 2022 21:35:48 +0200 Subject: [PATCH 05/10] add test for time.Time conversion --- go.mod | 2 ++ value_test.go | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 value_test.go diff --git a/go.mod b/go.mod index 049d681..ab49283 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/norunners/vert go 1.16 + +require github.com/corbym/gocrest v1.0.5 // indirect diff --git a/value_test.go b/value_test.go new file mode 100644 index 0000000..663852e --- /dev/null +++ b/value_test.go @@ -0,0 +1,22 @@ +package vert + +import ( + "github.com/corbym/gocrest/is" + "github.com/corbym/gocrest/then" + "testing" + "time" +) + +const isoStringLength = len("yyyy-MM-ddThh:mm:ss") + +func TestValueOfTime(t *testing.T) { + now := time.Now() + + jsVal := ValueOf(now) + + // cut of the timezone information, because seconds precision is sufficient for this test + jsValIsoString := jsVal.Call("toISOString").String() + jsValIsoString = jsValIsoString[:isoStringLength] + + then.AssertThat(t, jsValIsoString, is.EqualTo(now.UTC().Format(time.RFC3339)[:isoStringLength])) +} From d7d4538a636eca51a099484b0fee7320ae862692 Mon Sep 17 00:00:00 2001 From: nitram509 Date: Sat, 19 Nov 2022 14:05:05 +0100 Subject: [PATCH 06/10] refactor Time object transformation into valueOfStruct(), as requested by feedback --- value.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/value.go b/value.go index eb40538..d0f978b 100644 --- a/value.go +++ b/value.go @@ -38,10 +38,6 @@ func ValueOf(i interface{}) Value { // valueOf recursively returns a new value. func valueOf(v reflect.Value) js.Value { - if t, ok := v.Interface().(time.Time); ok { - dateConstructor := js.Global().Get("Date") - return dateConstructor.New(t.Format(time.RFC3339)) - } switch v.Kind() { case reflect.Ptr, reflect.Interface: return valueOfPointerOrInterface(v) @@ -95,6 +91,11 @@ func valueOfMap(v reflect.Value) js.Value { // valueOfStruct returns a new object value. func valueOfStruct(v reflect.Value) js.Value { + if t, ok := v.Interface().(time.Time); ok { + // special case: Time, instantiates a new js Date object + dateConstructor := js.Global().Get("Date") + return dateConstructor.New(t.Format(time.RFC3339)) + } t := v.Type() s := object.New() n := v.NumField() From e493b45d6f2c01086cadbe041f0cca60d4f1cc95 Mon Sep 17 00:00:00 2001 From: nitram509 Date: Sat, 19 Nov 2022 14:06:17 +0100 Subject: [PATCH 07/10] fix go.mod + go.sum via 'go mod tidy' --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 go.sum diff --git a/go.mod b/go.mod index ab49283..f26b81d 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/norunners/vert go 1.16 -require github.com/corbym/gocrest v1.0.5 // indirect +require github.com/corbym/gocrest v1.0.5 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0020080 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/corbym/gocrest v1.0.5 h1:6FUvLjKkKQ2hwMel8OKIZqN3slYEOHIFY9+lVaroFnU= +github.com/corbym/gocrest v1.0.5/go.mod h1:lF3xBPnOU5DYDpa/vUq63SMxUhd5UAwGgmA8Z2pJ/Tk= From 74c5b414c8a5bd1b7a443ba54fc94ebc66395d48 Mon Sep 17 00:00:00 2001 From: nitram509 Date: Sat, 19 Nov 2022 14:09:01 +0100 Subject: [PATCH 08/10] just empty line to trigger Github Action --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7cdec0a..4a18893 100644 --- a/README.md +++ b/README.md @@ -103,3 +103,4 @@ Package `vert` leverages and extends `syscall/js` to accommodate these shortcomi ## License * [MIT License](LICENSE) + From 5a5f4e7416471b94ba19ef59841bd5e2a6d7a516 Mon Sep 17 00:00:00 2001 From: nitram509 Date: Sat, 19 Nov 2022 14:23:29 +0100 Subject: [PATCH 09/10] upgrade actions/setup-go@v3 and actions/checkout@v3, because Github warnings: "Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: actions/setup-go@v2, actions/checkout@v2" remove former empty line to trigger Github Action --- .github/workflows/test.yml | 4 ++-- README.md | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e2bc400..039d562 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Setup - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} - name: Install chrome @@ -17,7 +17,7 @@ jobs: - name: Install wasmbrowsertest run: go install github.com/agnivade/wasmbrowsertest@latest - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Test env: GOOS: js diff --git a/README.md b/README.md index 4a18893..7cdec0a 100644 --- a/README.md +++ b/README.md @@ -103,4 +103,3 @@ Package `vert` leverages and extends `syscall/js` to accommodate these shortcomi ## License * [MIT License](LICENSE) - From 271f471d706eff497f89dd0ebe8f96208fa033d3 Mon Sep 17 00:00:00 2001 From: "Martin W. Kirst" Date: Sun, 20 Nov 2022 10:42:38 +0100 Subject: [PATCH 10/10] Update value_test.go Co-authored-by: Caleb Jasik --- value_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/value_test.go b/value_test.go index 663852e..ad79059 100644 --- a/value_test.go +++ b/value_test.go @@ -14,7 +14,7 @@ func TestValueOfTime(t *testing.T) { jsVal := ValueOf(now) - // cut of the timezone information, because seconds precision is sufficient for this test + // cut off the timezone information, because second's precision is sufficient for this test jsValIsoString := jsVal.Call("toISOString").String() jsValIsoString = jsValIsoString[:isoStringLength]