dontgo

package module
v0.0.0-...-967c33e Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2018 License: MIT Imports: 8 Imported by: 0

README

DontGo

GoDoc

An unofficial client for using dontpad.com with go. Create temporary online persistence.

dontpad.com

Dontpad is an online and easily shareable notepad. You can create and edit pages using any identifier simply by accessing dontpad.com/{identifier}

Installation

You can install with a simple go get
go get github.com/lucp2/dontgo

Usage

There are basically four methods you can call. All are exemplified here and documented in godoc.

package main

import(
    "github.com/lucp2/dontgo"
    "fmt"
)

func main() {
	// first lets write something in a page with the identifier "dontgo_test"
	// you can pass variables with any type to be written. With we can not simply convert it
	// to string, we will transform it into json.
	err := dontgo.Write("dontgo_test", "hello world")

	// now with access dontpad.com/dontgo_test we will see our "hello world" there

	// if there is anything wrong, we will tell you. 
	// What can go wrong are basically connection problems
	// or we couldn't convert what you passed to string (what did you pass?)
	if err != nil {
		fmt.Println(err)
		return
	}

	// we can also retrieve what we've just written
	a := dontgo.Read("dontgo_test")
	fmt.Println(a) //will print "hello world"

	// if there is anything wrong with the read function (such as connection), it will panic.
	// this is proposital, allowing you to use it directly as a value.
	// but if you don't this to happen, use ReadNoPanic instead.

	a, err = dontgo.ReadNoPanic("dontgo_test")
	if err != nil {
		// now you can treat it
		fmt.Println(err)
		return
	}
	fmt.Println(a) //will print "hello world"

	// the write function will overwrite anything that is already in the identifier's page.
	// if that is not your intention, use Append.
	err = dontgo.Append("dontgo_test", ", how you doing?")
	if err != nil {
		fmt.Println(err)
		return
	}

	// and if we read it again now
	a = dontgo.Read("dontgo_test")
	fmt.Println(a) //will print "hello world, how you doing?"

	// we can also clear a page simply by calling Clear
	err = dontgo.Clear("dontgo_test")
	if err != nil {
		fmt.Println(err)
		return
	}

	// and if we read it again now
	a = dontgo.Read("dontgo_test")
	fmt.Println(a) //will print nothing
}

Warning

Do not ever use this in production. First because this is unofficial and there is no guarantee that dontpad will not change the way they store the contents. And second because anyone is able to overwrite the identifiers without any authorization.

Documentation

Overview

Package dontgo is an unofficial client for using dontpad.com with go. It allows you to write and read in the dontpad website. You might want to use this package as a temporary way of applying persistence to your variables. Do not ever use this in production. First because this is unofficial and there is no guarantee that dontpad will not change the way they store the contents. And second because anyone is able to overwrite the identifiers without any authorization. You can also access what you wrote on the website dontpad.com/{identifier}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(identifier string, content interface{}) error

Append function is essentially the same as the Write function, excepts it does not overwrite the contents, if there is any, using the same identifier. It appends to the end of the previous content.

func Clear

func Clear(identifier string) error

Clear function deletes any content previously set using a identifier.

func Read

func Read(identifier string) (r string)

Read function gets an identifier and returns a string with its contents. You can also access it on dontpad.com/{identifier}. We do not return an error because we want you to be able to access it directly as value, if there are any errors, keep in mind that it will panic. If you don't want this to happen, use ReadNoPanic instead.

func ReadNoPanic

func ReadNoPanic(identifier string) (r string, err error)

ReadNoPanic function is essentially the same as Read function excepts it returns an error together with the value, allowing you to treat it.

func Write

func Write(identifier string, content interface{}) error

Write function receives a identifier string and an empty interface content, which contains what you want to write in the identifier page. You can pass pretty much anything, if it is any type of int, float or bool we will simply convert it into a string. If it is anything else, we will convert it to json with the builtin json package. If it can not convert, we will return its error so you can treat it. This function overwrites any previous content using the same identifier.

Types

This section is empty.

Jump to

Keyboard shortcuts

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