github.com/artisanhe/tools@v1.0.1-0.20210607022958-19a8fef2eb04/catgo/cat-go/DIFFERENCES.md (about)

     1  # Differences between gocat & gocat.v2
     2  
     3  ## Written in pure golang.
     4  
     5  `gocat.v2` is written in pure golang, which means it's no longer depend on [ccat](https://github.com/dianping/cat/tree/master/lib/c).
     6  
     7  And `CGO` is not required either.
     8  
     9  ## Cat instance is not required.
    10  
    11  In `gocat`, you have to create an instance like this:
    12  
    13  ```go
    14  import (
    15      "gocat"
    16  )
    17  
    18  cat := gocat.Instance()
    19  cat.LogEvent("foo", "bar")
    20  ```
    21  
    22  It is equal to the following codes in `gocat.v2`
    23  
    24  ```go
    25  import (
    26  	"github.com/Meituan-Dianping/cat-go/cat"
    27  )
    28  
    29  cat.LogEvent("foo", "bar")
    30  ```
    31  
    32  ## Event can be nested in Transaction.
    33  
    34  See [case1](./README.md#Example)
    35  
    36  ## API return value changes
    37  
    38  The following APIs **do not** return pointer anymore.
    39  
    40  ```go
    41  type Cat interface {
    42      func NewTransaction(mtype, name string) *message.Transaction
    43      func NewEvent(mtype, name string) *message.Event
    44      func NewMetricHelper(m_name string) *MetricHelper
    45  }
    46  ```
    47  
    48  Have changed to:
    49  
    50  ```go
    51  type Cat interface {
    52      func NewTransaction(mtype, name string) message.Transactor
    53      func NewEvent(mtype, name string) message.Messeger
    54      func NewMetricHelper(m_name string) MetricHelper
    55  }
    56  ```
    57  
    58  No influences if you have used `:=` or `var` to receive our returned value.
    59  
    60  ## API params changes
    61  
    62  The following APIs requires **time.Time** or **time.Duration** as parameter, which used to be `int64` (timestampInNanosecond).
    63  
    64  ```go
    65  type Message interface {
    66      SetTimestamp(timestampInNano int64)
    67      GetTimestamp() int64
    68  }
    69  
    70  type Transaction interface {
    71      SetDuration(durationInNano int64)
    72      GetDuration() int64
    73      
    74      SetDurationStart(durationStartInNano int64)
    75  }
    76  ```
    77  
    78  Have changed to:
    79  
    80  ```go
    81  type Message interface {
    82      SetTime(time time.Time)
    83      GetTime() time.Time
    84  }
    85  
    86  type Transaction interface {
    87      SetDuration(duration time.Duration)
    88      GetDuration() time.Duration
    89      
    90      SetDurationStart(time time.Time)
    91  }
    92  ```
    93  
    94  If you have used the mentioned APIs above, migrate to `gocat.v2` will take you some time.