Skip to content

Commit

Permalink
Merge pull request #9 from usk81/change-ci
Browse files Browse the repository at this point in the history
Change CI
  • Loading branch information
usk81 committed Aug 22, 2020
2 parents f095360 + b77276d commit f9cc29a
Show file tree
Hide file tree
Showing 15 changed files with 1,519 additions and 109 deletions.
24 changes: 24 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
categories:
- title: 'Bugfix'
labels:
- 'bugfix'
- 'bug'
- 'fix'
change-template: '- $TITLE (#$NUMBER) @$AUTHOR'
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
patch:
labels:
- 'patch'
default: patch
template: |
## Changes
$CHANGES
53 changes: 53 additions & 0 deletions .github/workflows/preliminary_review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: preliminary review
on:
pull_request

env:
GO111MODULE: on
GOPROXY: https://proxy.golang.org

jobs:
golangci:
name: linter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.30
# Optional: golangci-lint command line arguments.
args: --enable=goimports
test:
name: test
strategy:
matrix:
go-version: [1.12.x, 1.13.x, 1.14.x, 1.15.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Set GOPATH and PATH
run: |
echo "::set-env name=GOPATH::$(dirname $GITHUB_WORKSPACE)"
echo "::add-path::$(dirname $GITHUB_WORKSPACE)/bin"
shell: bash
- name: Checkout code
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ matrix.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ matrix.os }}-go-
- name: Test
run: go test --coverprofile=coverage.coverprofile --covermode=atomic ./...
- name: Upload coverage to Codecov
if: success() && matrix.go-version == '1.14.x' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v1
with:
fail_ci_if_error: false
19 changes: 19 additions & 0 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Release Drafter

on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master

jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
with:
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
config-name: release-drafter.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Generic
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/usk81/generic)
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/usk81/generic)
[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://github.com/usk81/generic/blob/master/LICENSE)
[![Build Status](http://img.shields.io/travis/usk81/generic.svg?style=flat-square)](https://travis-ci.org/usk81/generic)
[![Coverage Status](https://img.shields.io/coveralls/usk81/generic.svg?style=flat-square)](https://coveralls.io/github/usk81/generic?branch=master)
![](https://github.com/usk81/generic/workflows/preliminary%20review/badge.svg)
[![codecov](https://codecov.io/gh/usk81/generic/branch/master/graph/badge.svg)](https://codecov.io/gh/usk81/generic)
[![Go Report Card](https://goreportcard.com/badge/github.com/usk81/generic)](https://goreportcard.com/report/github.com/usk81/generic)

flexible data type for Go

support: Go 1.8+
support: Go 1.12+

## Install

Expand All @@ -26,7 +26,7 @@ package main

import (
"encoding/json"
"github.com/usk81/generic"
"github.com/usk81/generic/v2"
)

type User struct {
Expand Down
41 changes: 20 additions & 21 deletions convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,42 +37,41 @@ func asBool(x interface{}) (result bool, isValid ValidFlag, err error) {

// asBool converts a specified value to float64 value.
func asFloat(x interface{}) (result float64, isValid ValidFlag, err error) {
switch x.(type) {
switch v := x.(type) {
case nil:
return result, false, nil
case int:
result = float64(x.(int))
result = float64(v)
case int8:
result = float64(x.(int8))
result = float64(v)
case int16:
result = float64(x.(int16))
result = float64(v)
case int32:
result = float64(x.(int32))
result = float64(v)
case int64:
result = float64(x.(int64))
result = float64(v)
case uint:
result = float64(x.(uint))
result = float64(v)
case uint8:
result = float64(x.(uint8))
result = float64(v)
case uint16:
result = float64(x.(uint16))
result = float64(v)
case uint32:
result = float64(x.(uint32))
result = float64(v)
case uint64:
result = float64(x.(uint64))
result = float64(v)
case float32:
result = float64(x.(float32))
result = float64(v)
case float64:
result = x.(float64)
result = v
case bool:
b := x.(bool)
if b {
if v {
result = 1
} else {
result = 0
}
case string:
f, err := strconv.ParseFloat(x.(string), 64)
f, err := strconv.ParseFloat(v, 64)
if err != nil {
return result, false, ErrInvalidGenericValue{Value: x}
}
Expand Down Expand Up @@ -138,11 +137,11 @@ func asString(x interface{}) (result string, isValid ValidFlag, err error) {

// asBool converts a specified value to time.Time value.
func asTime(x interface{}) (result time.Time, isValid ValidFlag, err error) {
switch x.(type) {
switch v := x.(type) {
case nil:
return result, false, nil
case time.Time:
result = x.(time.Time)
result = v
if result.IsZero() {
return result, true, nil
}
Expand Down Expand Up @@ -248,13 +247,13 @@ func asTimestampWithFunc(x interface{}, f func(i int64) time.Time) (result time.
}

func asURL(x interface{}) (result *url.URL, isValid ValidFlag, err error) {
switch x.(type) {
switch v := x.(type) {
case nil:
return nil, false, nil
case *url.URL:
result = x.(*url.URL)
result = v
case string:
result, err = url.Parse(x.(string))
result, err = url.Parse(v)
default:
err = ErrInvalidGenericValue{Value: x}
}
Expand Down
22 changes: 11 additions & 11 deletions json_marshal_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func BenchmarkMarshalJSONBool(b *testing.B) {
bool: true,
}
for i := 0; i < b.N; i++ {
x.MarshalJSON()
x.MarshalJSON() // nolint
}
}

Expand All @@ -22,7 +22,7 @@ func BenchmarkMarshalJSONFloat(b *testing.B) {
float: 1000.000001,
}
for i := 0; i < b.N; i++ {
x.MarshalJSON()
x.MarshalJSON() // nolint
}
}

Expand All @@ -32,7 +32,7 @@ func BenchmarkMarshalJSONInt(b *testing.B) {
int: 10000,
}
for i := 0; i < b.N; i++ {
x.MarshalJSON()
x.MarshalJSON() // nolint
}
}

Expand All @@ -42,7 +42,7 @@ func BenchmarkMarshalJSONString(b *testing.B) {
string: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
}
for i := 0; i < b.N; i++ {
x.MarshalJSON()
x.MarshalJSON() // nolint
}
}

Expand All @@ -52,7 +52,7 @@ func BenchmarkMarshalJSONStringLarge(b *testing.B) {
string: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
}
for i := 0; i < b.N; i++ {
x.MarshalJSON()
x.MarshalJSON() // nolint
}
}

Expand All @@ -62,7 +62,7 @@ func BenchmarkMarshalJSONTime(b *testing.B) {
time: time.Now(),
}
for i := 0; i < b.N; i++ {
x.MarshalJSON()
x.MarshalJSON() // nolint
}
}

Expand All @@ -72,7 +72,7 @@ func BenchmarkMarshalJSONTimestampMS(b *testing.B) {
time: time.Now(),
}
for i := 0; i < b.N; i++ {
x.MarshalJSON()
x.MarshalJSON() // nolint
}
}

Expand All @@ -82,7 +82,7 @@ func BenchmarkMarshalJSONTimestampNano(b *testing.B) {
time: time.Now(),
}
for i := 0; i < b.N; i++ {
x.MarshalJSON()
x.MarshalJSON() // nolint
}
}

Expand All @@ -92,7 +92,7 @@ func BenchmarkMarshalJSONTimestamp(b *testing.B) {
time: time.Now(),
}
for i := 0; i < b.N; i++ {
x.MarshalJSON()
x.MarshalJSON() // nolint
}
}

Expand All @@ -102,7 +102,7 @@ func BenchmarkMarshalJSONUint(b *testing.B) {
uint: 10000,
}
for i := 0; i < b.N; i++ {
x.MarshalJSON()
x.MarshalJSON() // nolint
}
}

Expand All @@ -115,6 +115,6 @@ func BenchmarkMarshalJSONURL(b *testing.B) {
},
}
for i := 0; i < b.N; i++ {
x.MarshalJSON()
x.MarshalJSON() // nolint
}
}
Loading

0 comments on commit f9cc29a

Please sign in to comment.