netfunnel

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: MIT Imports: 9 Imported by: 0

README

NetFunnel-Go

A wrapper library of NetFunnel for Go

Before use

[!WARNING] NetFunnel API runs in a separate environment for each service you use, so you need to know in advance the API Endpoint of the NetFunnel for the service you want to use.

Install

$ go get github.com/antegral/netfunnel-go

Example

import (
	"net/http"
	"net/http/cookiejar"
	"net/url"

	"github.com/antegral/netfunnel-go"
)

const NETFUNNEL_API = "https://netfunnel.example.com/ts.wseq"
const APPLICATION_API = "https://api.example.com"

func main() {
  // 1. Create a Client struct for NetFunnel.
  nf := Netfunnel.Client{
    ApiEndpoint: NETFUNNEL_API,
    RetryInterval: 1 * time.Second,
  }

  // 2. Get a valid ticket for NetFunnel.
  // If the queue is full, it will wait for a ticket to become valid.
  ticket := nf.GetTicket()

  // 3. Put the ticket into the cookie jar.
  jar, _ := cookiejar.New(nil)
  var cookies []*http.Cookie
  cookie := &http.Cookie{
    Name:  "NetFunnel_ID",
    Value: ticket.Id,
  }
  cookies = append(cookies, cookie)
  jar.SetCookies(&url.URL{Host: APPLICATION_API}, cookies)

  // 4. Now use it as you would normally use a cookie jar.
  client := http.Client{
    Jar: jar,
  }

  // 5. Done!
  client.Post(APPLICATION_API, "application/json", nil)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	ApiEndpoint   string        // the netfunnel server endpoint. you should know that the netfunnel endpoint is different by the api server.
	RetryInterval time.Duration // if waitlist is full, delay time to check again. (recommend: 1s)
}

func (*Client) CheckWaitlist

func (t *Client) CheckWaitlist(key string) (int, error)

Check waitlist status from the server with the key.

if success, return 200.

func (*Client) DispatchTicket

func (t *Client) DispatchTicket(ticket *Ticket) error

Dispatching ticket to the server

func (*Client) GetTicket

func (t *Client) GetTicket() (Ticket, error)

Getting ticket from the server

type Ticket

type Ticket struct {
	Id    string
	Ip    string
	Key   string
	Nnext int
	Nwait int
	Port  int
	Tps   int
	Ttl   int
}

The netfunnel ticket struct.

if you need, you can to get ticket from the server by calling GetTicket() method. and if you can requesting another api server (using netfunnel), maybe you need this ID of the ticket.

Jump to

Keyboard shortcuts

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