ifsapi

package module
v0.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2026 License: MIT Imports: 10 Imported by: 0

README

go-ifsapi

Helper go module for dealing with the IFS Cloud API.

About

If you have ever had the displeasure of working with IFS you will know how crucial it is to build external tools to use the system effectively. This module provides a quick way to query the API and parse the response.

By default this module will log all requests. Logging can be configured or disabled entirely. See the Logger struct for more info. Disable with Client.DisableLogging().

Use

Add it to your project with:

$ go get codeberg.org/jrk/go-ifsapi

Example

The below example will pull all the users from the system and print their Identities.

RootUrl := "https://ifs-url.gov/main/ifsapplications/projection/v1"
Endpoint := "/UserHandling.svc/Users?$select=Identity"
ifsClient := ifsapi.NewClient(ClientID, ClientSecret, RefreshURL, RootURL)
res, err := ifsClient.Request(Endpoint, http.MethodGet, "")
if err != nil {
    log.Fatalf("%s\n", err)
}

for i := range len(res.Value) {
    val, err := res.ValueFromKeyNString("Identity", i)
    if err != nil {
        log.Printf("%s\n", err)
        continue
    }
    fmt.Printf("Identity %3d: %s\n", i, val)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValueMapNotSet = errors.New("value array not found in IFS response")
	ErrDataMapNotSet  = errors.New("data map was unable to be set")
	ErrValueTypeNil   = errors.New("value type is nil")
	ErrEmptyResponse  = errors.New("recieved an empty response")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	// Current oauth token
	Token string
	// URL to be used when refreshing the token
	TokenRefreshURL string
	// Client ID of the service user account in IFS
	ID string
	// Client secret of the service user account in IFS
	Secret string
	// The root url of the IFS api. This allows calling specific endpoints
	// without needing to provide the whole URL each time.
	RootURL string
	// Fully customizable logger enabled by default with sane defaults.
	// Disable with Client.DisableLogging().
	Log Logger
}

Client used to make requests and store the latest response

func NewClient

func NewClient(clientID, clientSecret, tokenRefreshURL, rootURL string) *Client

Creates a client Expects the IFS user clientID and clientSecret. As well as the url to issue refresh requests. Also takes the rootURL of the api for ex: "https://ifs.com/main/ifsapplications/projection/v1" This makes it less noisy when calling endpoints later as you just have to provide the endpoint not the whole url each time.

func (*Client) DisableLogging

func (c *Client) DisableLogging()

Disable client logging

func (*Client) EnableLogging

func (c *Client) EnableLogging()

Enable client logging

func (*Client) Request

func (c *Client) Request(endpoint, method, body string) (*Response, error)

Calls an IFS endpoint with the specified method and optional body. Return a Response or an an error on failure. If the call returns a 401 Unauthorized it will attempt to refresh the token and try again. If it fails again it will return an error.

type Logger

type Logger struct {
	Logger  *log.Logger
	Enabled bool
}

Wrapper around log.Logger to allow the user to disable logging.

func (*Logger) Disable

func (l *Logger) Disable()

Disables the logger. Can also set Logger.Enabled manually

func (*Logger) Enable

func (l *Logger) Enable()

Enables the logger. Can also set Logger.Enabled manually

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...any)

Wrapper around log.Logger.Printf checks to see if logging is enabled

func (*Logger) Println

func (l *Logger) Println(v ...any)

Wrapper around log.Logger.Println checks to see if logging is enabled

type Response

type Response struct {
	// Raw response from IFS
	DataRaw []byte
	// Response from IFS already mapped
	DataMap map[string]any
	// @odata.count if exists in the response if not found it will be -1
	Count int
	// IFS returned value array. Typically it will be an array of objects.
	Value []any
	// HTTP status code
	StatusCode int
}

The response from the IFS API

func (*Response) ValueFromKey

func (r *Response) ValueFromKey(key string) (any, error)

Returns the first value indexed by key in Response.ValueMap if it exists

func (*Response) ValueFromKeyMap added in v0.3.0

func (r *Response) ValueFromKeyMap(key string) (map[string]any, error)

Returns the first value indexed by key in Response.ValueMap as a map[string]any if it exists. Useful for converting value into a struct.

func (*Response) ValueFromKeyN

func (r *Response) ValueFromKeyN(key string, index int) (any, error)

Returns the value indexed by key in Response.ValueMap[index] if it exists.

func (*Response) ValueFromKeyNMap added in v0.3.0

func (r *Response) ValueFromKeyNMap(key string, index int) (map[string]any, error)

Returns the value indexed by key in Response.ValueMap[index] as a map[string]any if it exists. Useful for converting value into a struct.

func (*Response) ValueFromKeyNString added in v0.2.0

func (r *Response) ValueFromKeyNString(key string, index int) (string, error)

Returns the value indexed by key in Response.ValueMap[index] as a string if it exists.

func (*Response) ValueFromKeyString added in v0.2.0

func (r *Response) ValueFromKeyString(key string) (string, error)

Returns the first value indexed by key in Response.ValueMap as a string if it exists

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL