sl1

package
v0.0.0-...-c3023dc Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2021 License: GPL-3.0 Imports: 3 Imported by: 1

Documentation

Overview

Package sl1 Package account implements utility routines for manipulating /api

Index

Examples

Constants

View Source
const (
	AccountAPI = "/api/account"
)

These are predefined shortcuts for sl1 APIs sections.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicInfo

type BasicInfo []struct {
	URI         string `json:"URI"`
	Description string `json:"description"`
	ID          string
}

BasicInfo is an abstraction for primitives api results

func (*BasicInfo) FmtMsg

func (bInfo *BasicInfo) FmtMsg(i int) string

FmtMsg returns an user friendly output format based on provided index

func (*BasicInfo) ListByDesc

func (bInfo *BasicInfo) ListByDesc(args []string) ([]int, []error)

ListByDesc returns the list of index for provided description(s) lookup

func (*BasicInfo) Load

func (bInfo *BasicInfo) Load(api string) error

Load loads BasicInfo from /api/xyz

Example
package main

import (
	"fmt"
	"log"

	"github.com/marco-ostaska/sl1cmd/pkg/sl1"
	"github.com/marco-ostaska/sl1cmd/pkg/sl1/httpcalls"
)

func main() {

	var bInfo sl1.BasicInfo
	httpcalls.Insecure = true // just for testing purposes

	if err := bInfo.Load("/api/account"); err != nil {
		log.Fatalln(err)
	}

	fmt.Println(bInfo[0])

}
Output:

{/api/account/1 em7admin 1}

func (*BasicInfo) LookupDescByURI

func (bInfo *BasicInfo) LookupDescByURI(uri string) (string, error)

LookupDescByURI looks up a description content for a provided URI

Example
package main

import (
	"fmt"
	"log"

	"github.com/marco-ostaska/sl1cmd/pkg/sl1"
	"github.com/marco-ostaska/sl1cmd/pkg/sl1/httpcalls"
)

func main() {
	var bInfo sl1.BasicInfo
	httpcalls.Insecure = true // to accept invalid certificate

	if err := bInfo.Load("/api/account"); err != nil {
		log.Fatalln(err)
	}

	desc, err := bInfo.LookupDescByURI("/api/account/1")
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Println(desc)
}
Output:

em7admin

func (*BasicInfo) LookupIDbyDesc

func (bInfo *BasicInfo) LookupIDbyDesc(s string) (string, error)

LookupIDbyDesc looks up sl1id for a provided Description

Example
package main

import (
	"fmt"
	"log"

	"github.com/marco-ostaska/sl1cmd/pkg/sl1"
	"github.com/marco-ostaska/sl1cmd/pkg/sl1/httpcalls"
)

func main() {
	var bInfo sl1.BasicInfo
	httpcalls.Insecure = true // to accept invalid certificate

	if err := bInfo.Load("/api/account"); err != nil {
		fmt.Println(err)
	}

	sl1id, err := bInfo.LookupIDbyDesc("em7admin")
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Println(sl1id)

}
Output:

1

func (*BasicInfo) LookupIdxByDesc

func (bInfo *BasicInfo) LookupIdxByDesc(d string) (int, error)

LookupIdxByDesc lookups up index position for provided BasicInfo.Description

Example
package main

import (
	"fmt"
	"log"

	"github.com/marco-ostaska/sl1cmd/pkg/sl1"
	"github.com/marco-ostaska/sl1cmd/pkg/sl1/httpcalls"
)

func main() {
	var bInfo sl1.BasicInfo
	httpcalls.Insecure = true // to accept invalid certificate

	if err := bInfo.Load("/api/account"); err != nil {
		log.Fatalln(err)
	}

	i, err := bInfo.LookupIdxByDesc("em7admin")
	if err != nil {
		log.Fatalln(err)
	}

	fmt.Println(i)

}
Output:

0

Directories

Path Synopsis
Package httpcalls makes GET, DELETE and POST requests.
Package httpcalls makes GET, DELETE and POST requests.
Package vault manages encryption for sl1cmd credentials
Package vault manages encryption for sl1cmd credentials

Jump to

Keyboard shortcuts

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