Provides a simple way of constructing API endpoint calls with IntelliSense and chainable syntax.
packagemainimport ("encoding/json""fmt""log""github.com/koltyakov/gosip""github.com/koltyakov/gosip/api" strategy "github.com/koltyakov/gosip/auth/addin")funcmain() {// Getting auth params and client client, err :=getAuthClient()if err !=nil { log.Fatalln(err) }// Binding SharePoint API sp := api.NewSP(client)// Custom headers headers :=map[string]string{"Accept": "application/json;odata=minimalmetadata","Accept-Language": "de-DE,de;q=0.9", } config :=&api.RequestConfig{Headers: headers}// Chainable request sample data, err := sp.Conf(config).Web().Lists().Select("Id,Title").Get()if err !=nil { log.Fatalln(err) }// Response object unmarshalling// (struct depends on OData mode and API method) res :=&struct { Value []struct { ID string`json:"Id"` Title string`json:"Title"` } `json:"value"` }{}if err := json.Unmarshal(data, &res); err !=nil { log.Fatalf("unable to parse the response: %v", err) }for _, list :=range res.Value { fmt.Printf("%+v\n", list) }}funcgetAuthClient() (*gosip.SPClient, error) { configPath :="./config/private.spo-addin.json"// <- file with creds auth :=&strategy.AuthCnfg{}if err := auth.ReadConfig(configPath); err !=nil {returnnil, fmt.Errorf("unable to get config: %v", err) }return&gosip.SPClient{AuthCnfg: auth}, nil}
Generic HTTP-client helper
Provides generic GET/POST helpers for REST operations, reducing amount of http.NewRequest scaffolded code, can be used for custom or not covered with a Fluent API endpoints.
Low-lever SharePoint-aware HTTP client from github.com/koltyakov/gosip package for custom or not covered with a Fluent API client endpoints with granular control for HTTP request, response, and http.Client parameters. Used internally but almost never required in a consumer code.
SPClient has Execute method which is a wrapper function injecting SharePoint authentication and ending up calling http.Client's Do method.
Reference
Many auth flows have been "copied" from node-sp-auth library (used as a blueprint), which we intensively use in Node.js ecosystem for years.
Fluent API and wrapper syntax are inspired by PnPjs which is also the first-class citizen on almost all our Node.js and front-end projects with SharePoint involved.