lvlup

package module
v0.0.0-...-b106828 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: MIT Imports: 6 Imported by: 0

README

LvlUp client for Golang

Golang client for LvlUp api v4

Project status

Current codebase can be treated as a experiment which can be something different within an hour from now. Project will become stable with version 1.0. Until then be aware of the braking changes

This does not mean that you shouldn't use it. Any feedback is welcome! If you have any ideas on how to make this library better, or you see potential problem create an issue with a proper flag.

Quick Start

import (
  "net/http"
  "fmt"
)

func main() {
  httpClient := &http.Client{}
  client := lvlup.NewLvlCLient("<api_key>", httpClient)

  result, err := client.CreatePayment(
    "24.99",
    lvlup.WithRedirectUrl("<redirect_url>"),
    lvlup.WithWebhookUrl("<webhook_url>")
  )

  if err != nil {
    panic(err)
  }

  fmt.Println(result)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreatePaymentOption

type CreatePaymentOption func(*CreatePaymentOptions)

CreatePaymentOption represents a functional option for CreatePayment func.

func WithRedirect

func WithRedirect(url string) CreatePaymentOption

Set url to which user should be redirected after completing a payment.

func WithWebhook

func WithWebhook(url string) CreatePaymentOption

WithWebhook sets webhook url to which POST request will be send after completing a payment.

type CreatePaymentOptions

type CreatePaymentOptions struct {
	Amount      string `json:"amount"`
	RedirectUrl string `json:"redirectUrl"`
	WebhookUrl  string `json:"webhookUrl"`
}

CreatePaymentOptions represents available options for CreatePayment func.

type CreatePaymentResult

type CreatePaymentResult struct {
	Id  string `json:"id"`
	Url string `json:"url"`
}

CreatePaymentResult represents result of CreatePayment func.

type DDoSAttack

type DDoSAttack struct {
	Id        int    `json:"id"`
	Ip        string `json:"ip"`
	StartedAt int    `json:"startedAt"`
	EndedAt   int    `json:"endedAt"`
}

DDoSAttack represents single DDoS Attack.

type GetUDPFilterResult

type GetUDPFilterResult struct {
	FilteringEnabled bool   `json:"filteringEnabled"`
	State            string `json:"state"`
}

GetUDPFilterResult represents result of GetUDPFilter func.

type GetVPSStateResult

type GetVPSStateResult struct {
	Status    string `json:"status"`
	VmUptimeS int    `json:"vmUptimeS"`
}

GetVPSStateResult represents result of GetVPSState.

type InspectPaymentResult

type InspectPaymentResult struct {
	AmountInt        int    `json:"amountInt"`
	AmountStr        string `json:"amuntStr"`
	AmountWithFeeInt int    `json:"amountWithFeeInt"`
	AmountWithFeeStr string `json:"amountWithFeeStr"`
	Payed            bool   `json:"payed"`
}

InspectPaymentResult represents result of InspectPayment func.

type ListDDoSAttacksResult

type ListDDoSAttacksResult struct {
	Count int          `json:"count"`
	Items []DDoSAttack `json:"items"`
}

ListDDoSAttacksResult represents result of ListDDoSAttacks func.

type ListPaymentsOption

type ListPaymentsOption func(*ListPaymentsOptions)

ListPaymentsOption represents functional option for a ListPayments func.

func WithAfterId

func WithAfterId(afterId int) ListPaymentsOption

WithAfterId allows to set payment id after which payments should be returned.

func WithBeforeId

func WithBeforeId(beforeId int) ListPaymentsOption

WithBeforeId allows to set payment id before which payments should be returned.

func WithLimit

func WithLimit(limit int) ListPaymentsOption

WithLimit allows to set max payments count per page.

type ListPaymentsOptions

type ListPaymentsOptions map[string]string

ListPaymentsOptions represents a map storing optional query parameters for ListPayments func.

type ListPaymentsResult

type ListPaymentsResult struct {
	Count int                      `json:"count"`
	Items []ListPaymentsResultItem `json:"items"`
}

ListPaymentsResult represents result of ListPayments func.

type ListPaymentsResultItem

type ListPaymentsResultItem struct {
	Amount      string `json:"amount"`
	CreatedAt   string `json:"createdAt"`
	Description string `json:"description"`
	Id          int    `json:"id"`
	MethodId    int    `json:"methodId"`
	ServiceId   int    `json:"serviceId"`
}

ListPaymentsResultItem represents single item from ListPayments func.

type ListServicesResult

type ListServicesResult struct {
	Services []Service
}

ListServices represents result of ListServices func.

type LvlClient

type LvlClient struct {
	ApiKey      string
	ApiBase     string
	SandboxMode bool
	HttpClient  *http.Client
}

LvlClient describes properties stored by the client.

func NewLvlClient

func NewLvlClient(apiKey string, httpClient *http.Client, opts ...LvlClientOption) *LvlClient

NewLvlClient creates new lvlup api client.

func (LvlClient) AddUDPFilterException

func (lc LvlClient) AddUDPFilterException(vpsId string, exception *UDPFilterException) error

AddUDPFilterException allows to add exception for UDP filter.

func (LvlClient) CreatePayment

func (lc LvlClient) CreatePayment(amount string, opts ...CreatePaymentOption) (*CreatePaymentResult, error)

CreatePayment allows to create a new payment url. It returns result of a request and any errors encountered.

func (LvlClient) GetProxmoUser

func (lc LvlClient) GetProxmoUser(vpsId string) (*ProxmoUser, error)

GetProxmoUser allows to create new proxmo user, or reset password if already exists.

func (LvlClient) GetUDPFilter

func (lc LvlClient) GetUDPFilter(vpsId string) (*GetUDPFilterResult, error)

GetUDPFilter allows to check UDP filtering status for specified VPS.

func (LvlClient) GetVPSState

func (lc LvlClient) GetVPSState(vpsId string) (*GetVPSStateResult, error)

GetVPSState allows to get specified VPS state.

func (LvlClient) InspectPayment

func (lc LvlClient) InspectPayment(paymentId string) (*InspectPaymentResult, error)

InspectPayment allows to inspect a payment. It returns request result and any errors encountered.

func (LvlClient) ListDDoSAttacks

func (lc LvlClient) ListDDoSAttacks(vpsId string) (*ListDDoSAttacksResult, error)

ListDDoSAttacks allows to access list of DDoS attacks for specific VPS.

func (LvlClient) ListPayments

func (lc LvlClient) ListPayments(opts ...ListPaymentsOption) (*ListPaymentsResult, error)

ListPayments allows to list client's payments. It returns request result and eny errors encountered.

func (LvlClient) ListServices

func (lc LvlClient) ListServices() (*ListServicesResult, error)

ListServices allows to list all services like VPS or domains. It returns request result or any errors encountered.

func (LvlClient) ListUDPFilterExceptions

func (lc LvlClient) ListUDPFilterExceptions(vpsId string) ([]UDPFilterException, error)

ListUDPFilterExceptions allows to list all exceptions for UDP filter.

func (LvlClient) RemoveUDPFilterException

func (lc LvlClient) RemoveUDPFilterException(vpsId string, exceptionId string) error

RemoveUDPFilterException allows to remove exception for UDP filter.

func (LvlClient) SetUDPFiltering

func (lc LvlClient) SetUDPFiltering(vpsId string, filteringEnabled bool) (*SetUDPFilteringResult, error)

SetUDPFiltering allows to switch UDP filtering status for specified VPS on and off.

func (LvlClient) StartVPS

func (lc LvlClient) StartVPS(vpsId string) error

StartVps allows to start specified VPS server.

func (LvlClient) StopVPS

func (lc LvlClient) StopVPS(vpsId string) error

StopVPS allows to stop specified VPS.

func (LvlClient) WalletBalance

func (lc LvlClient) WalletBalance() (*WalletBalanceResult, error)

WalletBalance allows to get current wallet balance. It returns request result and any errors encountered.

type LvlClientOption

type LvlClientOption func(*LvlClient)

LvlClientOption describes functional option for the client.

func WithSandboxMode

func WithSandboxMode() LvlClientOption

WithSandboxMode enables sandbox mode for the LvlClient.

type ProxmoUser

type ProxmoUser struct {
	Password string `json:"password"`
	Url      string `json:"url"`
	Username string `json:"username"`
}

ProxmoUser represents proxmo user.

type Service

type Service struct {
	Id        int    `json:"id"`
	PlanName  string `json:"planName"`
	Active    bool   `json:"active"`
	CreatedAt string `json:"createdAt"`
	PayedTo   string `json:"payedTo"`
	Ip        string `json:"ip"`
	Name      string `json:"name"`
	NodeId    int    `json:"nodeId"`
	ServiceId int    `json:"serviceId"`
}

Service represents single service from ListServices func result.

type SetUDPFilteringOptions

type SetUDPFilteringOptions struct {
	FilteringEnabled bool `json:"filteringEnabled"`
}

SetUDPFilteringOptions represents available options for SetUDPFiltering func.

type SetUDPFilteringResult

type SetUDPFilteringResult struct {
	FilteringEnabled bool   `json:"filteringEnabled"`
	State            string `json:"state"`
}

SetUDPFilteringResult represents result of SetUDPFiltering func.

type UDPFilterException

type UDPFilterException struct {
	Id       int                       `json:"id"`
	Ports    []UDPFilterExceptionPorts `json:"ports"`
	Protocol string                    `json:"protocol"`
	State    string                    `json:"state"`
}

UDPFilterWhitelistException represents single exception.

type UDPFilterExceptionPorts

type UDPFilterExceptionPorts struct {
	From int `json:"form"`
	To   int `json:"to"`
}

UDPFilterExceptionPorts represents options for UDP filter exception ports.

type WalletBalanceResult

type WalletBalanceResult struct {
	BalancePlnFormatted string `json:"balancePlnFormatted"`
	BalancePlnInt       int    `json:"balancePlnInt"`
}

WalletBalanceResult represents result of WalletBalance request.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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