Skip to content

Commit

Permalink
jsoniter
Browse files Browse the repository at this point in the history
  • Loading branch information
sdfsdhgjkbmnmxc committed Sep 11, 2020
1 parent 35c19b4 commit b5bea3e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ go 1.14
require (
github.com/google/uuid v1.1.2
github.com/gorilla/websocket v1.4.2
github.com/json-iterator/go v1.1.10
github.com/pkg/errors v0.9.1
github.com/tada-team/tdproto v0.0.13
github.com/tada-team/tdproto v0.2.1
)

//replace github.com/tada-team/tdproto v0.0.13 => ../tdproto
14 changes: 14 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/tada-team/tdproto v0.0.3 h1:BCkh0cDz7EU778FmfpzEWn7Ifvl+KyYW+yttK339Kpc=
github.com/tada-team/tdproto v0.0.3/go.mod h1:VY1rTZXOhMxyZ1VE/Q82PB27AaFAooEQJFkO0HMlN8M=
github.com/tada-team/tdproto v0.0.7 h1:eGQQG+/QNwWp0savQmnirJ80gmMajsR2MI6fyzCPNi8=
github.com/tada-team/tdproto v0.0.7/go.mod h1:eQGUKL2y6C9EGrhOZY0HU7bb/5lBdVfHBlx2+e0l7x4=
github.com/tada-team/tdproto v0.0.12 h1:mVKzWHsu6rWyz1idWP6ewe5rCtThiU9CcukZiTo8URM=
github.com/tada-team/tdproto v0.0.12/go.mod h1:eQGUKL2y6C9EGrhOZY0HU7bb/5lBdVfHBlx2+e0l7x4=
github.com/tada-team/tdproto v0.2.1 h1:uCHXKzoETO1lvbpO9WEmgqhSp+PBmlxF+08m4cDUNQs=
github.com/tada-team/tdproto v0.2.1/go.mod h1:eQGUKL2y6C9EGrhOZY0HU7bb/5lBdVfHBlx2+e0l7x4=
5 changes: 5 additions & 0 deletions json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package tdclient

import jsoniter "github.com/json-iterator/go"

var json = jsoniter.ConfigCompatibleWithStandardLibrary
26 changes: 18 additions & 8 deletions session.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tdclient

import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
Expand All @@ -10,9 +9,8 @@ import (
"os"
"time"

"github.com/tada-team/tdproto"

"github.com/pkg/errors"
"github.com/tada-team/tdproto"
)

type apiResp struct {
Expand All @@ -25,18 +23,16 @@ type Session struct {
logger *log.Logger
server url.URL
token string
cookie string
features *tdproto.Features
}

func NewSession(server string, verbose bool) (Session, error) {
func NewSession(server string) (Session, error) {
s := Session{
Timeout: 10 * time.Second,
}

s.logger = log.New(os.Stdout, "tdclient: ", log.LstdFlags|log.Lmicroseconds|log.Lmsgprefix)
if !verbose {
s.logger.SetOutput(ioutil.Discard)
}

u, err := url.Parse(server)
if err != nil {
Expand All @@ -59,7 +55,21 @@ func (s *Session) Features() (*tdproto.Features, error) {
return s.features, nil
}

func (s *Session) SetToken(token string) { s.token = token }
func (s *Session) SetToken(v string) {
s.token = v
}

func (s *Session) SetCookie(v string) {
s.cookie = v
}

func (s *Session) SetVerbose(v bool) {
if v {
s.logger.SetOutput(os.Stdout)
} else {
s.logger.SetOutput(ioutil.Discard)
}
}

func (s Session) Ping() error {
resp := new(struct {
Expand Down
1 change: 0 additions & 1 deletion ws.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tdclient

import (
"encoding/json"
"fmt"
"log"
"net/http"
Expand Down

0 comments on commit b5bea3e

Please sign in to comment.