Skip to content

Commit

Permalink
add documents
Browse files Browse the repository at this point in the history
  • Loading branch information
shockerli committed Sep 6, 2022
1 parent 6b2fd72 commit 8907124
Show file tree
Hide file tree
Showing 235 changed files with 4,192 additions and 23 deletions.
1 change: 1 addition & 0 deletions doc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.hugo_build.lock
6 changes: 6 additions & 0 deletions doc/archetypes/default.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true
---

27 changes: 27 additions & 0 deletions doc/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
baseURL = "https://cvt.shockerli.net"
title = "cvt"
theme = "hugo-geekdoc"

defaultContentLanguage = 'en'

pluralizeListTitles = false

# Geekdoc required configuration
pygmentsUseClasses = true
pygmentsCodeFences = true
disablePathToLower = true

# Required if you want to render robots.txt template
enableRobotsTXT = true

# Needed for mermaid shortcodes
[markup]
[markup.goldmark.renderer]
# Needed for mermaid shortcode
unsafe = true
[markup.tableOfContents]
startLevel = 1
endLevel = 9

[taxonomies]
tag = "tags"
10 changes: 10 additions & 0 deletions doc/config/_default/languages.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
en:
languageName: "English"
contentDir: "content/en"
weight: 10

zh-cn:
languageName: "简体中文"
contentDir: "content/zh-cn"
weight: 20
95 changes: 95 additions & 0 deletions doc/content/en/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
title: 'Go type conversion'
geekdocNav: false
geekdocAlign: center
geekdocAnchor: false
---

<!-- markdownlint-capture -->
<!-- markdownlint-disable MD033 -->

<span class="badge-placeholder">[![PkgGoDev](https://pkg.go.dev/badge/github.com/shockerli/cvt)](https://pkg.go.dev/github.com/shockerli/cvt)</span>
<span class="badge-placeholder">[![Go Report Card](https://goreportcard.com/badge/github.com/shockerli/cvt)](https://goreportcard.com/report/github.com/shockerli/cvt)</span>
<span class="badge-placeholder">[![Build Status](https://travis-ci.com/shockerli/cvt.svg?branch=master)](https://travis-ci.com/shockerli/cvt)</span>
<span class="badge-placeholder">[![codecov](https://codecov.io/gh/shockerli/cvt/branch/master/graph/badge.svg)](https://codecov.io/gh/shockerli/cvt)</span>
<span class="badge-placeholder">![GitHub](https://img.shields.io/github/license/shockerli/cvt)</span>
<span class="badge-placeholder">[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)</span>

<!-- markdownlint-restore -->

Simple, safe conversion of any type, including indirect/custom types.

{{< button size="large" relref="usage/getting-started" >}}Getting Started{{< /button >}}

## Feature overview

{{< columns >}}

### Safety

Support to any data type, no panic, safe with application.

<--->

### Lightweight

Less code, zero depend, the application almost no heavy burden.

<--->

### Easily

Semantic clarity, naming, documentation, detailed, directly get started.

{{< /columns >}}

## Examples

{{< tabs "index-example" >}}
{{< tab "WITH ERROR" >}}
```go
cvt.IntE("12") // 12, nil
cvt.Float64E("12.34") // 12.34, nil
cvt.StringE(12.34) // "12.34", nil
cvt.BoolE("false") // false, nil
```
{{< /tab >}}

{{< tab "IGNORE ERROR" >}}
```go
cvt.Int("12") // 12(success)
cvt.Int(struct{}{}) // 0(failed)
```
{{< /tab >}}

{{< tab "WITH DEFAULT" >}}
```go
cvt.Int(struct{}{}, 12) // 12
cvt.Float("hello", 12.34) // 12.34
```
{{< /tab >}}

{{< tab "CUSTOM TYPE" >}}
```go
type Name string

var name Name = "jioby"

cvt.StringE(name) // jioby, nil
```
{{< /tab >}}

{{< tab "INDIRECT" >}}
```go
var name = "jioby"

cvt.StringE(&name) // jioby, nil
```
{{< /tab >}}

{{< tab "POINTER" >}}
```go
cvt.BoolP("true") // (*bool)(0x14000126180)(true)
```
{{< /tab >}}

27 changes: 27 additions & 0 deletions doc/content/en/develop/32bit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Test in 32bit
weight: 10
---


Use `i386/golang:alpine` image for testing 32bit system, detail in `Dockerfile.32bit`



- build image

```shell
docker build -t cvt-test -f Dockerfile.32bit .
```

- run container

```shell
docker run -it --name cvt-test -v "$PWD":/usr/src/myapp -w /usr/src/myapp cvt-test bash
```

- run test

```shell
go test ./...
```
4 changes: 4 additions & 0 deletions doc/content/en/develop/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Development
weight: 30
---
4 changes: 4 additions & 0 deletions doc/content/en/type/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Type
weight: 20
---
51 changes: 51 additions & 0 deletions doc/content/en/type/bool.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: Bool
weight: 10
---

{{< toc >}}



## Bool
Convert an interface to a bool type, with default value.

```go
cvt.Bool(0) // false
cvt.Bool(nil) // false
cvt.Bool("0") // false
cvt.Bool("false") // false
cvt.Bool([]int{}) // false

cvt.Bool(true) // true
cvt.Bool("true") // true
cvt.Bool([]int{1, 2}) // true
cvt.Bool([]byte("true")) // true
```

## BoolE
Convert an interface to a bool type.

```go
cvt.BoolE(0) // false,nil
cvt.BoolE(nil) // false,nil
cvt.BoolE("0") // false,nil
cvt.BoolE("false") // false,nil
cvt.BoolE([]int{}) // false,nil

cvt.BoolE(true) // true,nil
cvt.BoolE("true") // true,nil
cvt.BoolE([]int{1, 2}) // true,nil
cvt.BoolE([]byte("true")) // true,nil
```

## BoolP
Convert and store in a new bool value, and returns a pointer to it.

```go
cvt.BoolP("true") // (*bool)(0x14000126180)(true)
```

## More Examples
More case see unit: `bool_test.go`

39 changes: 39 additions & 0 deletions doc/content/en/type/float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Float
weight: 30
---


{{< toc >}}


## Function
- Float32
- Float32E
- Float32P
- Float64
- Float64E
- Float64P


## Examples
```go
cvt.Float64(int32(8)) // 8
cvt.Float64(float32(8.31)) // 8.31
cvt.Float64("-8") // 8
cvt.Float64("-8.01") // 8.01
cvt.Float64(nil) // 0
cvt.Float64(true) // 1
cvt.Float64(false) // 0

type AliasTypeInt int
type PointerTypeInt *AliasTypeInt
cvt.Float64(AliasTypeInt(8)) // 8
cvt.Float64((*AliasTypeInt)(nil)) // 0
cvt.FLoat64((*PointerTypeInt)(nil)) // 0

cvt.Float64P("12.3") // (*float64)(0x14000126180)(12.3)
```

> More case see unit: `float_test.go`
64 changes: 64 additions & 0 deletions doc/content/en/type/int.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
title: Int
weight: 20
---


{{< toc >}}



## Function
- Int
- IntE
- IntP
- Int8
- Int8E
- Int8P
- Int16
- Int16E
- Int16P
- Int32
- Int32E
- Int32P
- Int64
- Int64E
- Int64P
- Uint
- UintE
- UintP
- Uint8
- Uint8E
- Uint8P
- Uint16
- Uint16E
- Uint16P
- Uint32
- Uint32E
- Uint32P
- Uint64
- Uint64E
- Uint64P

## Examples
```go
cvt.Int(int8(8)) // 8
cvt.Int(int32(8)) // 8
cvt.Int("-8.01") // -8
cvt.Int([]byte("8.00")) // 8
cvt.Int(nil) // 0
cvt.IntE("8a") // 0,err
cvt.IntE([]int{}) // 0,err

// alias type
type OrderType uint8
cvt.Int(OrderType(3)) // 3

var po OrderType = 3
cvt.Int(&po) // 3

cvt.IntP("12") // (*int)(0x140000a4180)(12)
```

> More case see unit: `int_test.go`
35 changes: 35 additions & 0 deletions doc/content/en/type/map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: Map
weight: 70
---

{{< toc >}}


## StringMapE

- Map
```go
// expect: map[string]interface{}{"111": "cvt", "222": 3.21}
cvt.StringMapE(map[interface{}]interface{}{111: "cvt", "222": 3.21})
```

- Struct

```go
// expect: map[string]interface{}{"Name": "cvt", "Age": 3}
cvt.StringMapE(struct {
Name string
Age int
}{"cvt", 3})
```

- JSON
```go
// expect: map[string]interface{}{"name": "cvt", "age": 3.21}
cvt.StringMapE(`{"name":"cvt","age":3.21}`)
```


> More case see unit: `map_test.go`
Loading

0 comments on commit 8907124

Please sign in to comment.