lafi = lark + feishu
go-lafi is a Go client library for accessing the Lark/Feishu API.
As of now I am writing this library, there is no official Lark/Feishu SDK for Go.Although Bytedance is the fastest growing tech company in China,seems like they don't want to hire a Go developer to write a Go SDK for Lark/Feishu. 😂
The goals of this library are:
- Provide a complete and idiomatic Go client for the Feishu API.
- Ensure that the library is well tested and documented.
- Practice my Go skills.🤖️
go get github.com/joyqi/go-lafi
Initialize Lark client with OAuth2 authentication:
import"github.com/joyqi/go-lafi/oauth2"varconf=&oauth2.Config{AppID:"your-client-id",AppSecret:"your-client-secret",RedirectURL:"your-redirect-url",}
For Feishu, you can specify theType
field toTypeFeishu
:
import"github.com/joyqi/go-lafi/oauth2"varconf=&oauth2.Config{AppID:"your-client-id",AppSecret:"your-client-secret",RedirectURL:"your-redirect-url",Type:oauth2.TypeFeishu,}
Get the authorization URL:
url:=conf.AuthCodeURL("your-state")
Exchange the authorization code for an access token:
token,err:=conf.Exchange(ctx,code)
Use TokenSource to persist the token and refresh it as needed:
ts:=conf.TokenSource(ctx,token)token,err:=ts.Token()
Features:
Initialize API client:
import"github.com/joyqi/go-lafi/oauth2"client:=conf.TenantTokenSource(ctx).Client()
Use the client to access the API. For example, to list all groups:
import ("github.com/joyqi/go-lafi/oauth2""github.com/joyqi/go-lafi/api/contact")client:=conf.TenantTokenSource(ctx).Client()api:=&contact.Group{Client:client}api.SimpleList(&contact.GroupSimpleListParams{PageSize:100,})