tools

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

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

Go to latest
Published: May 28, 2023 License: Apache-2.0 Imports: 0 Imported by: 0

README

Octools

stand lib

get max and min from target array

max,min:=tools.MaxandMin(your_array_name)

reverse string

yourstringname=tools.Reverse(yourstringname)

sort array

//normal sort
yourarrayname=tools.Sort(yourarrayname)
//sort plus
yourarrayname=tools.SortPlus(yourarrayname,sort_postion)

getbasename and dirpath

basename:=toolsbox.GetBaseName(path)
dirpath:=toolsbox.GetDirPath(path)

read conf from ini file.default conf file path:conf/site-conf.ini

keyvaluemap:=remindmetools.ReadConfPlus(keyarray) //input a array that should include your all key you want,and it will return a key : value map to you

DataBase Tutorial

You can use mysql database easier than before.It's based on github.com/jmoiron/sqlx
  • Insert into table (...)values(...)
    // insert into user_info (id,name,password)values("oc awesome","oswaldoooo","it's great!")
    err := dbcontroller.Insert(map[string]string{"id": "'" + template.HTMLEscapeString("oc awesome") + "'", "name": "'" + template.HTMLEscapeString("oswaldoooo") + "'", "password": "'" + template.HTMLEscapeString("it's great!") + "'"})
    //or use inserteasily.
    err:=dbcontroller.InsertEasily(map[string]string{"id":"oc awesome","name":"oswaldoooo","password":"it's great!"})
    
  • select ... from table where ...=...
    //select id,name,password from user_info where id='oc awesome'
    userinfo := struct{ Id, Name, Password string }{}
    err = dbcontroller.Get(&userinfo, "id", "'oc awesome'", "id", "name", "password")
    
  • update table set ...... where ....
    //update user_info set name='oswaldo' where id='oc awesome'
    err = dbcontroller.Update(map[string]string{"name": "'oswaldo'"}, "id", "'oc awesome'")
    // or use UpdateEasily
    err=dbcontroller.UpdateEasily(map[string]string{"name":"oswaldo","id":"oc awesome"})
    
  • delete from table where ...
    err = dbcontroller.Delete("id", "'oc awesome'")
    

JwtToken Tutorial

It's based on github.com/golang-jwt/jwt

  • Register jwttoken service
    //this method will use default claims to create token
    jt := jwttoken.NewJwt()
    
  • Generate A New Token
    //you can put your user's unimportant data into the map,then generate a new token for user
    token,err:=jt.GenerateToken(map[string]string{})
    
  • Parse The Token
    //claim.Args is the map you put in when you generate the token
    claim, err := jt.ParseToken(token)
    

BinarySearch

//the default match rate is 50%
datasotre.BinarySearch(content,origin_array)[]string

Pluginer Tutorial

quick start your plugin mode in your program

  • prepare your plugin configuration file.It should look like this
    <?xml version="1.0" encoding="UTF-8"?>
    <plugin_info>
            <!-- the name is your plugin file's name.you can contain '.so',or not -->
        <plugin classname="test" name="greet"/>
        <!-- here is your own path that your project.and your project directory should also contains plugin directory.the directory name is 'plugin'-->
        <rootpath>/Users/oswaldo/dev/golang/examples</rootpath>
    </plugin_info>
    
  • set the pluginer in your project
    var coremap = map[string]func(*plugin.Plugin) error{"test": loadnormal}
    //here is the path of your plugin configuration file.And the coremap(map[classname]parsing method)
    pluginer, err := pluginer.CreatePluginer("/Users/oswaldo/dev/golang/examples/site.xml", coremap)
    
  • and your parsing method should like this
    //input *plugin.Plugin,return error
    func(*plugin.Plugin)error
    //this is an example
    func loadnormal(pluginer *plugin.Plugin) (err error) {
        srm, err := pluginer.Lookup("Pattern")
        if err == nil {
            pattern := *srm.(*string)
            srm, err = pluginer.Lookup("Greet")
            if err == nil {
                resfunc := srm.(func(string, *int) error)
                testfunc[pattern] = resfunc
            }
        }
        return
    }
    
  • finally,set your plugin method as global variable

Terminal

Process Bar

ProBar:=toolsbox.ProcessInit('=')//init process bar,and fill by char '='
go ProcessRun(ProBar)//listen the program's process
for i:=0;i<100;i++{
    ProBar.Pos<-uint(i)//tell the program's process
}
toolsbox.ProcessFinished(ProBar)//finished the process,dont care finished more,it'll be finished when it not finished,or do nothing there

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxandMin

func MaxandMin[T int | float32 | float64](value []T) (T, T)

find max and min from your array.example:max,min:=MaxandMin(your arrary)

func Reverse

func Reverse(value string) string

simple to reverse string to string Reverse('hello')->olleh

func Sort

func Sort[T int | float32 | float64](value []T) []T

sort array example:Sort(yourarray)->(sort from high to low)

func Sortplus

func Sortplus[T int | float32 | float64](value [][]T, post int) [][]T

sort Two-dimensional array

Types

type DBarray

type DBarray[T int | float32 | float64 | string | bool | byte] struct {
	Key    []byte
	Value  []T
	Langth int
}

func Newarray

func Newarray[T int | float32 | float64 | string | bool | byte](key string, value []T) (*DBarray[T], bool)

type DBkeys

type DBkeys[T int | float32 | float64 | string | bool] struct {
	Key    []byte
	Value  T
	Langth int
}

func NewKey

func NewKey[T int | float32 | float64 | string | bool](key string, value T) (*DBkeys[T], bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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