Skip to content

refactor #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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