Coder Social home page Coder Social logo

zerobounce-go's Introduction

ZeroBounce Email Verification Library for Go

Getting Started

You will need a zerobounce account to get started.
Once you get an account, you will need to get an api key to use it in the API calls.

Installation

Require the package

$ go get https://github.com/twisted1919/zerobounce-go

Go Version

Requires Go >= 1.8

Usage

package main

import (
	"fmt"
	"github.com/twisted1919/zerobounce-go"
	"log"
	"net/netip"
)

// Example function to show available credits
func credits(api *zerobounce.API) {
	response, err := api.GetCredits()
	if err != nil {
		log.Fatal(fmt.Errorf("unable to fetch the credits: %w", err))
	}

	if response.IsSuccess() {
		fmt.Println("you have", response.Success.Credits, "credits left")
	} else if response.IsError() {
		fmt.Println("the api returned following error", response.Error.Error)
	}
}

// Example function to validate an email address
func validate(api *zerobounce.API, email string, ipAddress *netip.Addr) {
	response, err := api.Validate(email, ipAddress)
	if err != nil {
		log.Fatal(fmt.Errorf("unable to validate email address: %w", err))
	}

	if response.IsSuccess() {
		fmt.Println("the email address", email, "is", response.Success.Status)
	} else if response.IsError() {
		fmt.Println("the api returned following error", response.Error.Error)
	}
}

func main() {

	// instantiate the api
	api := zerobounce.NewAPI("your-api-key")

	// output the result of validation call for a valid email address
	validate(api, "[email protected]", nil)

	// output the result of validation call for an invalid email address
	validate(api, "[email protected]", nil)

	// output the result of validation call for an valid email address but for a different IP Address
	ipAddress := netip.MustParseAddr("127.0.0.1")
	validate(api, "[email protected]", &ipAddress)

	// output the result of the get credits call
	credits(api)

}

License

MIT

Test

Set your api key in the ZEROBOUNCE_API_KEY environment variable, then run:

$ go test ./...

Bug Reports

Report here.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.