Code Monkey home page Code Monkey logo

tool's Introduction

TOOL

English | 简体中文

Overview

  • Build HTTP and GRPC services
  • Quickly build SQL conditional statements
  • The LRU cache、local cache
  • Filters include Bloom and Cuckoo
  • The unique ID can be GUID, NanoID, Snowflake, or UUID
  • The Websocket、socket
  • Parameter validator
  • Type conversion
  • Verify the characters、AES、DES、RSA
  • Prometheus monitoring and link tracing
  • A distributed lock
  • The log level
  • Current limiter

SQL Where

  • conditional statements are built quickly
import (
  "github.com/wjoj/tool"
)

type Account struct{
    Name `json:"name" gorm:"column:name" ifs:"="`
}

whs := NewWhereStructureFuncIfs(&Account{
    Name: "wjoj",
} , "gorm column", func(key string) string {
   if key == "name" {
       return "="
   }
   return "="
})

wh := new(tool.Where)
wh.AndIf("phone","like", "%28%")
wh.AndWhereStructure(whs, "or")

Socket

type Message struct {
    Lng uint32
    I   uint16
    Msg string
}

Server

SocketListen(899, func(s *SocketConn) error {
    readMsg := new(Message)
    err := s.ReadBody().Numerical(&readMsg.Lng)
    if err != nil {
        t.Errorf("\nReadBody error  lng:%+v	err:%v", readMsg.Lng, err)
        return err
    }
    err = s.ReadBody().Numerical(&readMsg.I)
    if err != nil {
        t.Errorf("\nReadBody error  ri:%v	err:%v", readMsg.I, err)
        return err
    }
    body, err := s.ReadBody().Body(int64(readMsg.Lng))
    if err != nil {
        t.Errorf("\nBody error  ri:%v	err:%v", len(body), err)
        return err
    }
    readMsg.Msg = string(body)
    t.Logf("\nread body succ msg:%+v", readMsg)
    msgb := fmt.Sprintf("server:%+v kkkkkkk", readMsg.I)
    writeMsg := &Message{
        Msg: msgb,
        Lng: uint32(len(msgb)),
        I:   readMsg.I,
    }

    msg := NewBodyWrite()
    msg.Numerical(&writeMsg.Lng)
    msg.Numerical(&writeMsg.I)
    msg.Write([]byte(writeMsg.Msg))
    _, err = s.WriteBody(msg)
    if err != nil {
        t.Errorf("\nWriteBody error i:%+v err:%v", writeMsg.I, err)
        return err
    }
    t.Logf("\nwrite body succ:%+v", writeMsg.I)
    // time.Sleep(time.Second * 2)
    return nil
})

Client

for i := uint16(0); i < uint16(t.N); i++ {
    // fmt.Printf("\ni:%+v", i)
    j := i
    SocketClient("127.0.0.1:899", func(s *SocketConn) error {
        msgb := fmt.Sprintf("client:%+v", i)
        writeMsg := &Message{
            Msg: msgb,
            Lng: uint32(len(msgb)),
            I:   j,
        }
        msg := NewBodyWrite()
        err := msg.Numerical(writeMsg.Lng)
        if err != nil {
            // t.Fatalf("WriteBody error  lng i:%+v	err:%v", j, err)
            return err
        }
        err = msg.Numerical(&writeMsg.I)
        if err != nil {
            // t.Fatalf("\nWriteBody error  i i:%+v	err:%v", j, err)
            return err
        }
        _, err = msg.Write([]byte(writeMsg.Msg))
        if err != nil {
            // t.Fatalf("\nWriteBody error  body i:%+v	err:%v", j, err)
            return err
        }
        _, err = s.WriteBody(msg)
        if err != nil {
            // t.Fatalf("\nWriteBody error i:%+v	err:%v", j, err)
            return err
        }
        // t.Logf("\nWriteBody succ i:%+v	", j)
        readMsg := new(Message)
        err = s.ReadBody().Numerical(&readMsg.Lng)
        if err != nil {
            // t.Fatalf("\nReadBody error i:%v lng:%+v err:%v", j, readMsg.Lng, err)
            return err
        }
        err = s.ReadBody().Numerical(&readMsg.I)
        if err != nil {
            // t.Fatalf("\nReadBody error i:%+v  ri:%v	err:%v", j, readMsg.I, err)
            return err
        }
        body, err := s.ReadBody().Body(int64(readMsg.Lng))
        if err != nil {
            // t.Fatalf("\nBody error i:%+v  ri:%v	err:%v", j, len(body), err)
            return err
        }
        readMsg.Msg = string(body)
        // t.Logf("\nread body i:%v msg:%+v", j, readMsg)
        time.Sleep(time.Second * 2)
        return nil
    })
}

tool's People

Contributors

wjoj avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.