-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package card | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"github.com/chyroc/lark" | ||
) | ||
|
||
type face struct { | ||
x uintptr | ||
data unsafe.Pointer | ||
} | ||
|
||
func isNil(v any) bool { | ||
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
Check failure on line 14 in card/if.go GitHub Actions / run
|
||
return (*face)(unsafe.Pointer(&v)).data == nil | ||
} | ||
|
||
func removeNilMessageContentCardModule(data []lark.MessageContentCardModule) []lark.MessageContentCardModule { | ||
res := make([]lark.MessageContentCardModule, 0, len(data)) | ||
for _, v := range data { | ||
if isNil(v) { | ||
continue | ||
} | ||
res = append(res, v) | ||
} | ||
return res | ||
} | ||
|
||
func removeNilMessageContentCardElement(data []lark.MessageContentCardElement) []lark.MessageContentCardElement { | ||
res := make([]lark.MessageContentCardElement, 0, len(data)) | ||
for _, v := range data { | ||
if isNil(v) { | ||
continue | ||
} | ||
res = append(res, v) | ||
} | ||
return res | ||
} | ||
|
||
func removeNilMessageContentCardObjectOption(data []*lark.MessageContentCardObjectOption) []*lark.MessageContentCardObjectOption { | ||
res := make([]*lark.MessageContentCardObjectOption, 0, len(data)) | ||
for _, v := range data { | ||
if isNil(v) { | ||
continue | ||
} | ||
res = append(res, v) | ||
} | ||
return res | ||
} | ||
|
||
func removeNilMessageContentCardModuleColumn(data []*lark.MessageContentCardModuleColumn) []*lark.MessageContentCardModuleColumn { | ||
res := make([]*lark.MessageContentCardModuleColumn, 0, len(data)) | ||
for _, v := range data { | ||
if isNil(v) { | ||
continue | ||
} | ||
res = append(res, v) | ||
} | ||
return res | ||
} | ||
|
||
func removeNilString(data []string) []string { | ||
res := make([]string, 0, len(data)) | ||
for _, v := range data { | ||
if isNil(v) { | ||
continue | ||
} | ||
res = append(res, v) | ||
} | ||
return res | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// +build go1.18 | ||
|
||
package card | ||
|
||
func If[T any](cond bool, val T, otherwise T) T { | ||
if cond { | ||
return val | ||
} | ||
return otherwise | ||
} | ||
|
||
func IfLay[T any](cond bool, val func() T, otherwise func() T) T { | ||
if cond { | ||
return val() | ||
} | ||
return otherwise() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module github.com/chyroc/lark | ||
|
||
go 1.16 | ||
go 1.18 | ||
|
||
require github.com/stretchr/testify v1.8.2 |