kutt

package module
v0.0.0-...-1447afc Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2021 License: MIT Imports: 8 Imported by: 0

README

kutt-go

Kutt.it API Client for Go and CLI tool

Kutt.it is a Modern Open Source URL shortener.

  • Custom domain
  • Password for the URL
  • Managing links
  • Free & Open Source
  • 50 URLs shortening per day.

This is a Go wrapper for the API and CLI tool. To get shorter url, you need to signup at Kutt.it and obtain API key from settings.

$ go get -u github.com/raahii/kutt-go

Usage

This is a example to get shorter url. The full example is in _example directory.

For API details, please refer official repository.

package main

import (
	"fmt"
	"log"

	"github.com/raahii/kutt-go"
)

func main() {
	cli := kutt.NewClient("<api key>")

	// create shorter url for this repository
	target := "https://github.com/raahii/kutt-go"
	URL, err := cli.Submit(
		target,
		// kutt.WithCustomURL("kutt-go"),
		// kutt.WithPassword("foobar"),
		// kutt.WithReuse(true),
	)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(URL.ShortURL) // https://kutt.it/kutt-go
}
type URL struct {
	ID         string    `json:"id"`
	Target     string    `json:"target"`
	ShortURL   string    `json:"shortUrl"`
	Password   bool      `json:"password"`
	Reuse      bool      `json:"reuse"`
	DomainID   string    `json:"domain_id"`
	VisitCount int       `json:"visit_count"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

CLI

$ go get -u github.com/raahii/kutt-go/cmd/kutt

You can register your API key to CLI with kutt apikey <key>.

❯ kutt --help
CLI tool for Kutt.it (URL Shortener)

Usage:
  kutt [command]

Available Commands:
  apikey      Register your api key to cli
  delete      Delete a shorted link (Give me url id or url shorted)
  list        List of last 5 URL objects.
  submit      Submit a new short URL
  help        Help about any command

Flags:
  -k, --apikey string   api key for Kutt.it
  -h, --help            help for kutt

Use "kutt [command] --help" for more information about a command.

Licence

Code released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTPClient *http.Client
	ApiKey     string
	BaseURL    string
	UserAgent  string
}

func NewClient

func NewClient(apiKey string, baseURL string) *Client

func (*Client) Delete

func (cli *Client) Delete(ID string, opts ...DeleteOption) error

func (*Client) List

func (cli *Client) List() ([]*URL, error)

func (*Client) Submit

func (cli *Client) Submit(target string, opts ...SubmitOption) (*URL, error)

type DeleteOption

type DeleteOption func(*DeleteParams)

func WithDomain

func WithDomain(v string) DeleteOption

type DeleteParams

type DeleteParams struct {
	ID     string  `json:"id"`
	Domain *string `json:"domain"`
}

type SubmitOption

type SubmitOption func(*SubmitParams)

func WithCustomURL

func WithCustomURL(v string) SubmitOption

func WithPassword

func WithPassword(v string) SubmitOption

func WithReuse

func WithReuse(v bool) SubmitOption

type SubmitParams

type SubmitParams struct {
	URL       string  `json:"target"`
	CustomURL *string `json:"customurl"`
	Password  *string `json:"password"`
	Reuse     *bool   `json:"reuse"`
}

type URL

type URL struct {
	ID         string    `json:"id"`
	Target     string    `json:"target"`
	ShortURL   string    `json:"shortUrl"`
	Password   bool      `json:"password"`
	Reuse      bool      `json:"reuse"`
	DomainID   string    `json:"domain_id"`
	VisitCount int       `json:"visit_count"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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