Skip to content

Commit

Permalink
Merge pull request #3 from golang-infrastructure/dev
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
CC11001100 authored Nov 21, 2022
2 parents 821882f + 3a03da8 commit 5ebcb5e
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 1,494 deletions.
Binary file removed .README_images/26e47025.png
Binary file not shown.
29 changes: 9 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
# Golang的三元表达式实现

# 开发初衷
# 一、开发初衷

Golang中缺少三元表达式,就导致某些情况三元表达式一行就能搞定的事情到Golang里面就得写得很啰嗦, 这是无法忍受的,这个库就是借助大量自定义的if函数来实现类似三元表达式的功能。
Golang中缺少三元表达式,就导致某些情况三元表达式一行就能搞定的事情到Golang里面就得写得很啰嗦,
这是无法忍受的,这个库就是借助大量自定义的if函数来实现类似三元表达式的功能。

## 引入依赖

非泛型版本:

```
go get -u github.com/golang-infrastructure/go-if-expression/v1
```

泛型版本:
## 二、引入依赖

```text
go get -u github.com/golang-infrastructure/go-if-expression/v2
go get -u github.com/golang-infrastructure/go-if-expression
```

# V1 Example

所有的API都在if_expression包下,根据三元表达式返回的不同类型有不同的名字:
![](.README_images/26e47025.png)
# 三、 Example

比如最常见的默认值场景:

Expand All @@ -30,16 +20,14 @@ threadNum := 0
fmt.Printf("线程数: %d", if_expression.ReturnInt(threadNum == 0, 1, threadNum))
```



# V2 Example
使用的例子:

```go
package main

import (
"fmt"
if_expression "github.com/golang-infrastructure/go-if-expression/v2"
if_expression "github.com/golang-infrastructure/go-if-expression"
)

func main() {
Expand All @@ -50,5 +38,6 @@ func main() {
//

}

```

2 changes: 1 addition & 1 deletion v2/example/main.go → example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"fmt"
"github.com/golang-infrastructure/go-if-expression/v2/pkg/if_expression"
if_expression "github.com/golang-infrastructure/go-if-expression"
)

func main() {
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/golang-infrastructure/go-if-expression

go 1.18
File renamed without changes.
File renamed without changes.
13 changes: 0 additions & 13 deletions v1/examples/default_value.go

This file was deleted.

3 changes: 0 additions & 3 deletions v1/go.mod

This file was deleted.

Loading

0 comments on commit 5ebcb5e

Please sign in to comment.