Skip to content

Commit

Permalink
0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
3JoB committed Feb 6, 2023
1 parent d11d23e commit 462e390
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 23 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"andybalholm",
"brotli",
"chatid",
"fsutil",
"gjson",
"klauspost",
"supergroup",
Expand Down
46 changes: 33 additions & 13 deletions fsutil/File.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,54 @@ package fsutil
import (
"bufio"
"os"

"github.com/3JoB/telebot/pkg"
)

func TruncWrite(d , v string) error {
file, err := os.OpenFile(d, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
if err != nil {
return err
type fsutil_struct struct{
Path string
Data string
TRUNC bool
}

func NewFile(path string) *fsutil_struct {
fs := &fsutil_struct{
Path: path,
}
defer file.Close()
writer := bufio.NewWriter(file)
writer.WriteString(v)
writer.Flush()
return nil
return fs
}

func (f *fsutil_struct) SetTrunc() *fsutil_struct {
if f.TRUNC {
f.TRUNC = false
} else {
f.TRUNC = true
}
return f
}

func Write(d , v string)error {
file, err := os.OpenFile(d, os.O_WRONLY|os.O_CREATE, 0666)
func (f *fsutil_struct) Write(d string) error {
var (
file *os.File
err error
)
if f.TRUNC {
file, err = os.OpenFile(f.Path, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
} else {
file, err = os.OpenFile(f.Path, os.O_WRONLY|os.O_CREATE, 0666)
}
if err != nil {
return err
}
defer file.Close()
writer := bufio.NewWriter(file)
writer.WriteString(v)
writer.Write(pkg.Bytes(d))
writer.Flush()
return nil
}

type f_info struct{}

func FileInfo(filepath string) *f_info {
func (f *fsutil_struct) Info(filepath string) *f_info {
return nil
}
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module github.com/3JoB/ulib

go 1.19
go 1.20

require (
github.com/3JoB/telebot v0.0.0-20230202125641-52c8068af540
github.com/3JoB/telebot v0.0.0-20230206093018-d4bc9140380f
github.com/andybalholm/brotli v1.0.4
github.com/gin-gonic/gin v1.8.2
github.com/goccy/go-json v0.10.0
Expand All @@ -23,6 +23,7 @@ require (
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.11.2 // indirect
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/3JoB/telebot v0.0.0-20230202125641-52c8068af540 h1:FNktUWKR3sSaw/TMU9jRMEq4oCeC6Kk4gvY2ikoNWCE=
github.com/3JoB/telebot v0.0.0-20230202125641-52c8068af540/go.mod h1:MevyoMQ8Z2Ba3w63lGAUhGDoWs/llHBCN/p3O4h2Gbw=
github.com/3JoB/telebot v0.0.0-20230206093018-d4bc9140380f h1:7G/ari6DQTh+6/bI+UkCKeDgroVn5QpvjV71P2Zh/7Q=
github.com/3JoB/telebot v0.0.0-20230206093018-d4bc9140380f/go.mod h1:/5lZ+FTI/7qV+94/5F/UKgZaqEjidzsqFXq303xCO0Q=
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY=
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/atreugo/mock v0.0.0-20200601091009-13c275b330b0 h1:IVqe9WnancrkICl5HqEfGjrnkQ4+VsU5fodcuFVoG/A=
Expand Down Expand Up @@ -32,6 +32,8 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd h1:PpuIBO5P3e9hpqBD0O/HjhShYuM6XE0i/lbE6J94kww=
github.com/grafana/regexp v0.0.0-20221122212121-6b5c0a4cb7fd/go.mod h1:M5qHK+eWfAv8VR/265dIuEpL3fNfeC21tXXp9itM24A=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY=
Expand Down
4 changes: 4 additions & 0 deletions json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func (m *marshal) String() string {
return pkg.String(m.data)
}

func (m *marshal) Bytes() []byte{
return m.data
}

func Unmarshal(data []byte, str any) error {
return gjs.Unmarshal(data, str)
}
Expand Down
22 changes: 16 additions & 6 deletions net/client/unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ import (

var decoder, _ = zstd.NewReader(nil, zstd.WithDecoderConcurrency(0))

func UnPackData(r *http.Response) ([]byte, error) {
return upk(r)
type update struct{
data []byte
Err error
}

func UnPackDataString(r *http.Response) (string, error) {
data, err := upk(r)
udt := pkg.String(data)
return udt, err
func Data(r *http.Response) *update {
upd := new(update)
upd.data, upd.Err = upk(r)
return upd
}

func (u *update) String() string {
udt := pkg.String(u.data)
return udt
}

func (u *update) Bytes() []byte {
return u.data
}

func upk(r *http.Response) ([]byte, error) {
Expand Down
22 changes: 22 additions & 0 deletions net/server/Bind.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package server

import (
"io"

"github.com/3JoB/telebot/pkg"
"github.com/3JoB/ulib/json"
)

/*gin:
server.Bind(c.Request.Body, &v)
*/
func Bind(r io.ReadCloser, v any) {
data, _ := io.ReadAll(r)
json.Unmarshal(data, v)
}

func Body(r io.ReadCloser, l int64) string {
body := make([]byte, l)
r.Read(body)
return pkg.String(body)
}

0 comments on commit 462e390

Please sign in to comment.