Files

icap-client

License Project status GoDoc

Talk to the ICAP servers using probably the first ICAP client package in GO!

Installing

go get -u github.com/egirna/icap-client

Usage

Import The Package

import ic "github.com/egirna/icap-client"

Making a simple RESPMOD call

  req, err := ic.NewRequest(context.Background(), MethodRESPMOD, "icap://<host>:<port>/<path>", httpReq, httpResp)
  if err != nil {
    log.Fatal(err)
  }

  client, err := ic.NewClient(
    ic.WithICAPConnectionTimeout(5 * time.Second),
  )
  if err != nil {
    log.Fatal(err)
  }

  resp, err := client.Do(req)
  if err != nil {
    log.Fatal(err)
  }

Note: httpReq & httpResp here are *http.Response & *http.Request respectively

Setting preview obtained from OPTIONS call

  req, err := ic.NewRequest(context.Background(), ic.MethodOPTIONS, "icap://<host>:<port>/<path>", nil, nil)
  if err != nil {
    log.Fatal(err)
  }

  client, err := ic.NewClient(
    ic.WithICAPConnectionTimeout(5 * time.Second),
  )
  if err != nil {
    log.Fatal(err)
  }

  req.SetPreview(optReq.PreviewBytes)

  // do something with req(ICAP *Request)

By default, the icap-client will dump the debugging logs to the standard output(stdout), but you can always add your custom writer

  f, _ := os.OpenFile("logs.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
  ic.SetDebugOutput(f)

For more details, see the docs and examples.

Contributing

This package is still WIP, so totally open to suggestions. See the contribution guide here.

License

icap-client is licensed under the Apache License.