Go SDK for working with the Nightfall Developer Platform

Nightfall Go SDK

nightfall-go-sdk is a Go client library for accessing the Nightfall API. It allows you to add functionality to your applications to scan plain text and files in order to detect different categories of information. You can leverage any of the detectors in Nightfall's pre-built library, or you may programmatically define your own custom detectors.

Additionally, this library provides convenience features such as encapsulating the steps to chunk and upload files.

To obtain an API Key, login to the Nightfall dashboard and click the section titled "Manage API Keys".

See our developer documentation for more details about integrating with the Nightfall API.

Installation

Nightfall Go SDK is compatible with modern Go releases in module mode, with Go installed:

go get github.com/nightfallai/nightfall-go-sdk

will resolve and add the package to the current development module, along with its dependencies.

Usage

Scanning Plain Text

Nightfall provides pre-built detector types, covering data types ranging from PII to PHI to credentials. The following snippet shows an example of how to scan using pre-built detectors.

Sample Code

nc, err := nightfall.NewClient()
if err != nil {
    log.Printf("Error initializing client: %v", err)
    return
}

resp, err := nc.ScanText(context.Background(), &nightfall.ScanTextRequest{
    Payload: []string{"4242 4242 4242 4242 is my ccn"},
    Config:  &nightfall.Config{
        // A rule contains a set of detectors to scan with
        DetectionRules:     []nightfall.DetectionRule{{
            // Define some detectors to use to scan your data
            Detectors: []nightfall.Detector{{
                MinNumFindings:    1,
                MinConfidence:     nightfall.ConfidencePossible,
                DisplayName:       "cc#",
                DetectorType:      nightfall.DetectorTypeNightfallDetector,
                NightfallDetector: "CREDIT_CARD_NUMBER",
            }},
            LogicalOp: nightfall.LogicalOpAny,
        },
        },
    },
})
if err != nil {
    log.Printf("Error scanning text: %v", err)
    return
}

Scanning Files

Scanning common file types like PDF's or office documents typically requires cumbersome text extraction methods like OCR.

Rather than implementing this functionality yourself, the Nightfall API allows you to upload the original files, and then we'll handle the heavy lifting.

The file upload process is implemented as a series of requests to upload the file in chunks. The library provides a single method that wraps the steps required to upload your file. Please refer to the API Reference for more details.

The file is uploaded synchronously, but as files can be arbitrarily large, the scan itself is conducted asynchronously. The results from the scan are delivered by webhook; for more information about setting up a webhook server, refer to the docs.

Sample Code

nc, err := nightfall.NewClient()
if err != nil {
    log.Printf("Error initializing client: %v", err)
    return
}

f, err := os.Open("./ccn.txt")
if err != nil {
    log.Printf("Error opening file: %v", err)
    return
}
defer f.Close()

fi, err := f.Stat()
if err != nil {
    log.Printf("Error getting file info: %v", err)
    return
}

resp, err := nc.ScanFile(context.Background(), &nightfall.ScanFileRequest{
    Policy: &nightfall.ScanPolicy{
        // File scans are conducted asynchronously, so provide a webhook route to an HTTPS server to send results to.
        WebhookURL: "https://my-service.com/nightfall/listener",
        // A rule contains a set of detectors to scan with
        DetectionRules: []nightfall.DetectionRule{{
            // Define some detectors to use to scan your data
            Detectors: []nightfall.Detector{{
                MinNumFindings:    1,
                MinConfidence:     nightfall.ConfidencePossible,
                DisplayName:       "cc#",
                DetectorType:      nightfall.DetectorTypeNightfallDetector,
                NightfallDetector: "CREDIT_CARD_NUMBER",
            }},
            LogicalOp: nightfall.LogicalOpAny,
        },
        },
    },
    RequestMetadata: "{\"hello\": \"world\", \"goodnight\": \"moon\"}",
    Content:          f,
    ContentSizeBytes: fi.Size(),
    Timeout:          0,
})
if err != nil {
    log.Printf("Error scanning file: %v", err)
    return
}
Similar Resources

Golang module for working with VK API

VK SDK for Golang VK SDK for Golang ready implementation of the main VK API functions for Go. Russian documentation Features Version API 5.131. API 40

Dec 10, 2022

A Go client for working with the Cryptohopper API

GoGoCryptohopper A Go client for working with the Cryptohopper API Structure of the client Request/Response The definitions for request and response f

Dec 23, 2021

Repo for working on Cloud-based projects in Go

GoCloud Repo for working on Cloud-based projects in Go AWS checkout SDK: https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/gov2/s3 cd into /ho

Jan 10, 2022

Gophercises-quiz-one - Working solution of Gophercises Quiz 1 Course

Gophercises Quiz 1 Working Solution Description Create a program that will read

Feb 2, 2022

AWS SDK for the Go programming language.

AWS SDK for Go aws-sdk-go is the official AWS SDK for the Go programming language. Checkout our release notes for information about the latest bug fix

Dec 31, 2022

A Facebook Graph API SDK For Go.

A Facebook Graph API SDK In Golang This is a Go package that fully supports the Facebook Graph API with file upload, batch request and marketing API.

Dec 12, 2022

A Golang SDK for Medium's OAuth2 API

Medium SDK for Go This repository contains the open source SDK for integrating Medium's OAuth2 API into your Go app. Install go get github.com/Medium/

Nov 28, 2022

MinIO Client SDK for Go

MinIO Go Client SDK for Amazon S3 Compatible Cloud Storage The MinIO Go Client SDK provides simple APIs to access any Amazon S3 compatible object stor

Dec 29, 2022

Simple no frills AWS S3 Golang Library using REST with V4 Signing (without AWS Go SDK)

simples3 : Simple no frills AWS S3 Library using REST with V4 Signing Overview SimpleS3 is a golang library for uploading and deleting objects on S3 b

Nov 4, 2022
Comments
  • Do not reuse http request on retry

    Do not reuse http request on retry

    It's not safe to reuse a request with a body parameter, so refactor our retry handler to construct a new request on each retry attempt.

    https://github.com/golang/go/issues/19653#issuecomment-341539160 https://go-review.googlesource.com/c/go/+/75671

  • Add support for AlertConfig

    Add support for AlertConfig

    Callers may provide an alertConfig object as part of either a synchronous plaintext scan, or an asynchronous file scan to fan alerts out to any of { slack, email, and webhook}.

  • Add support for defaultRedactionConfig

    Add support for defaultRedactionConfig

    Plaintext scan endpoint now supports a new field 'defaultRedactionConfig'. When set, this specifies how all findings should be redacted; this default configuration can be overridden at the detector level.

Go package providing opinionated tools and methods for working with the `aws-sdk-go/service/cloudfront` package.

go-aws-cloudfront Go package providing opinionated tools and methods for working with the aws-sdk-go/service/cloudfront package. Documentation Tools $

Feb 2, 2022
Nextengine-sdk-go: the NextEngine SDK for the Go programming language

NextEngine SDK for Go nextengine-sdk-go is the NextEngine SDK for the Go programming language. Getting Started Install go get github.com/takaaki-s/nex

Dec 7, 2021
Commercetools-go-sdk is fork of original commercetools-go-sdk

commercetools-go-sdk The Commercetools Go SDK is automatically generated based on the official API specifications of Commercetools. It should therefor

Dec 13, 2021
Sdk-go - Go version of the Synapse SDK

synapsesdk-go Synapse Protocol's Go SDK. Currently in super duper alpha, do not

Jan 7, 2022
Redash-go-sdk - An SDK for the programmatic management of Redash, in Go
Redash-go-sdk - An SDK for the programmatic management of Redash, in Go

Redash Go SDK An SDK for the programmatic management of Redash. The main compone

Dec 13, 2022
An easy-to-use unofficial SDK for Feishu and Lark Open Platform

go-lark go-lark is an easy-to-use unofficial SDK for Feishu and Lark Open Platform. go-lark implements messaging APIs, with full-fledged supports on b

Jan 2, 2023
Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://developer.github.com/v4/).

githubv4 Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql). If you're looking for a client

Dec 26, 2022
A GO API library for working with Marathon

Go-Marathon Go-marathon is a API library for working with Marathon. It currently supports Application and group deployment Helper filters for pulling

Dec 28, 2022
This is a Golang wrapper for working with TMDb API. It aims to support version 3.
This is a Golang wrapper for working with TMDb API. It aims to support version 3.

This is a Golang wrapper for working with TMDb API. It aims to support version 3. An API Key is required. To register for one, head over to themoviedb

Dec 27, 2022