Skip to content
This repository has been archived by the owner on Oct 24, 2018. It is now read-only.

Commit

Permalink
change variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
dcb9 committed Jun 20, 2018
1 parent a2700cb commit 0bfb0f5
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 84 deletions.
2 changes: 1 addition & 1 deletion boast.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package boast

import (
"net/http/httptest"
_ "github.com/dcb9/boast/inits/log"
"net/http/httptest"

"github.com/dcb9/boast/config"
"github.com/dcb9/boast/transaction"
Expand Down
6 changes: 3 additions & 3 deletions transaction/reverseProxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strings"
"time"

"github.com/google/uuid"
"context"
"github.com/google/uuid"
)

var via string
Expand Down Expand Up @@ -41,7 +41,7 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error
{
id, _ := uuid.NewUUID()

t := Ts{
t := Tx{
ID: id,
Req: tsReq,
Resp: NewResp(resp),
Expand All @@ -50,7 +50,7 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error
EndAt: endAt,
}

go TsHub.Add(t)
go TxHub.Add(t)
}

return resp, nil
Expand Down
10 changes: 5 additions & 5 deletions transaction/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/google/uuid"
)

var TsHub = NewHub()
var TxHub = NewTxHub()

var transport = &Transport{http.DefaultTransport}

Expand All @@ -30,15 +30,15 @@ func Serve() {
}

func Replay(id uuid.UUID) {
ts := TsHub.Transactions[id]
tx := TxHub.Transactions[id]

body := ioutil.NopCloser(bytes.NewReader(ts.Req.Body))
req, err := http.NewRequest(ts.Req.Method, ts.Req.URL.String(), body)
body := ioutil.NopCloser(bytes.NewReader(tx.Req.Body))
req, err := http.NewRequest(tx.Req.Method, tx.Req.URL.String(), body)
if err != nil {
log.Println(err)
return
}
req.Header = CopyHeader(ts.Req.Header)
req.Header = CopyHeader(tx.Req.Header)
_, err = transport.RoundTrip(req)
if err != nil {
log.Println(err)
Expand Down
14 changes: 7 additions & 7 deletions transaction/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ type Resp struct {
Status string `json:"Status"`
}

type Ts struct {
ID uuid.UUID `json:"ID"`
Req *Req `json:"Req"`
Resp *Resp `json:"Resp"`
ClientAddr string `json:"ClientAddr"`
BeginAt time.Time `json:"BeginAt"`
EndAt time.Time `json:"EndAt"`
type Tx struct {
ID uuid.UUID `json:"ID"`
Req *Req `json:"Req"`
Resp *Resp `json:"Resp"`
ClientAddr string `json:"ClientAddr"`
BeginAt time.Time `json:"BeginAt"`
EndAt time.Time `json:"EndAt"`
}

func NewReq(req *http.Request) *Req {
Expand Down
23 changes: 12 additions & 11 deletions transaction/transactionHub.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,36 @@ package transaction
import (
"sync"

"encoding/json"
"fmt"
"github.com/boltdb/bolt"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/boltdb/bolt"
"log"
"fmt"
"encoding/json"
)

const MAX_TRANSACTIONS_LEN int = 8 * 1024

var s sync.Mutex

var AddChannel chan *Ts = make(chan *Ts)
var AddChannel chan *Tx = make(chan *Tx)

type Hub struct {
Transactions map[uuid.UUID]*Ts
Transactions map[uuid.UUID]*Tx
SortID []uuid.UUID
}

func NewHub() *Hub {
func NewTxHub() *Hub {
hub := &Hub{
Transactions: make(map[uuid.UUID]*Ts),
Transactions: make(map[uuid.UUID]*Tx),
SortID: make([]uuid.UUID, 0, 32*1024),
}
hub.Init()
return hub
}

var db *bolt.DB

func (h *Hub) Init() {
var err error
db, err = bolt.Open("my.db", 0600, nil)
Expand All @@ -55,7 +56,7 @@ func (h *Hub) Init() {
c := b.Cursor()

for k, v := c.First(); k != nil; k, v = c.Next() {
var t Ts
var t Tx
err = json.Unmarshal(v, &t)
if err != nil {
log.Println("json.Unmarshal err ", err)
Expand All @@ -73,7 +74,7 @@ func (h *Hub) Init() {
}
}

func (h *Hub) Add(t Ts) error {
func (h *Hub) Add(t Tx) error {
if t.ID == uuid.Nil {
return errors.New("Transcation id MUST BE set.")
}
Expand Down Expand Up @@ -104,9 +105,9 @@ func (h *Hub) Add(t Ts) error {
return nil
}

func (h *Hub) List() []*Ts {
func (h *Hub) List() []*Tx {
length := len(h.SortID)
list := make([]*Ts, 0, len(h.SortID))
list := make([]*Tx, 0, len(h.SortID))
for i := 0; i < length; i++ {
transaction := h.Transactions[h.SortID[i]]
list = append(list, transaction)
Expand Down
50 changes: 25 additions & 25 deletions web/bindata_assetfs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
"log"
"net/http"

"bytes"
"fmt"
"github.com/dcb9/boast/config"
"github.com/dcb9/boast/transaction"
"github.com/dcb9/boast/web/ws"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/google/uuid"
"strings"
"io"
"bytes"
"strings"
)

var wsHub = ws.NewHub()
var tsHub = transaction.TsHub
var tsHub = transaction.TxHub

func Serve() {
go wsHub.Run()
Expand Down
Loading

0 comments on commit 0bfb0f5

Please sign in to comment.