Official Wikimedia Enterprise SDK for Go programming language.
See our api documentation and website for more information about the APIs.
- installing the SDK:
go get github.com/wikimedia-enterprise/wme-sdk-go- expose your credentials (if you don't have credentials already, sign up):
Create a .env file with the following contents:
export WME_USERNAME="...your username...";
export WME_PASSWORD="...your password...";- obtain your access token:
package main
import (
"context"
"log"
"os"
"github.com/wikimedia-enterprise/wme-sdk-go/pkg/auth"
)
func main() {
ctx := context.Background()
ath := auth.NewClient()
lgn, err := ath.Login(ctx, &auth.LoginRequest{
Username: os.Getenv("WME_USERNAME"),
Password: os.Getenv("WME_PASSWORD"),
})
if err != nil {
log.Fatalln(err)
}
log.Println(lgn.AccessToken)
}Auth APIs The following are the main authentication APIs provided by the SDK:
Login RefreshToken RevokeToken Helper APIs These helper APIs provide reference implementations for clients on how token state management can be done and how tokens can be used in concurrent processes using WME APIs:
GetAccessToken ClearState Example Usage
- putting it all together and making your first API call (we will be querying the Structured Contents endpoint, which is part of the On-demand API)
package main
import (
"context"
"log"
"os"
"github.com/wikimedia-enterprise/wme-sdk-go/pkg/api"
"github.com/wikimedia-enterprise/wme-sdk-go/pkg/auth"
)
func main() {
ctx := context.Background()
ath := auth.NewClient()
lgn, err := ath.Login(ctx, &auth.LoginRequest{
Username: os.Getenv("WME_USERNAME"),
Password: os.Getenv("WME_PASSWORD"),
})
if err != nil {
log.Fatalln(err)
}
defer func() {
req := &auth.RevokeTokenRequest{
RefreshToken: lgn.RefreshToken,
}
if err := ath.RevokeToken(ctx, req); err != nil {
log.Println(err)
}
}()
acl := api.NewClient()
acl.SetAccessToken(lgn.AccessToken)
req := &api.Request{
Fields: []string{"name", "abstract"},
Filters: []*api.Filter{
{
Field: "in_language.identifier",
Value: "en",
},
},
}
scs, err := acl.GetStructuredContents(ctx, "Squirrel", req)
if err != nil {
log.Fatalln(err)
}
for _, sct := range scs {
log.Println(sct.Name)
log.Println(sct.Abstract)
}
}- additional examples, such as connecting to the streaming API, can be found here