mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package protocol
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
protocolpb "go.temporal.io/api/protocol/v1"
|
|
)
|
|
|
|
type (
|
|
// Type is a protocol type of which there may be many instances like the
|
|
// update protocol or the query protocol.
|
|
Type string
|
|
|
|
// MessageType is the type of a message within a protocol.
|
|
MessageType string
|
|
|
|
constErr string
|
|
)
|
|
|
|
const (
|
|
MessageTypeUnknown = MessageType("__message_type_unknown")
|
|
TypeUnknown = Type("__protocol_type_unknown")
|
|
|
|
errNilMsg = constErr("nil message")
|
|
errNilBody = constErr("nil message body")
|
|
errProtoFmt = constErr("failed to extract protocol type")
|
|
errNoName = constErr("no message name specified")
|
|
)
|
|
|
|
// String transforms a MessageType into a string
|
|
func (mt MessageType) String() string {
|
|
return string(mt)
|
|
}
|
|
|
|
// String tranforms a Type into a string
|
|
func (pt Type) String() string {
|
|
return string(pt)
|
|
}
|
|
|
|
// Identify is a function that given a protocol message gives the specific
|
|
// message type of the body and the type of the protocol to which this message
|
|
// belongs.
|
|
func Identify(msg *protocolpb.Message) (Type, MessageType, error) {
|
|
if msg == nil {
|
|
return TypeUnknown, MessageTypeUnknown, errNilMsg
|
|
} else if msg.Body == nil {
|
|
return TypeUnknown, MessageTypeUnknown, errNilBody
|
|
}
|
|
|
|
bodyTypeName := string(msg.Body.MessageName())
|
|
if bodyTypeName == "" {
|
|
return TypeUnknown, MessageTypeUnknown, errNoName
|
|
}
|
|
|
|
msgType := MessageType(bodyTypeName)
|
|
lastDot := strings.LastIndex(bodyTypeName, ".")
|
|
if lastDot < 0 {
|
|
err := fmt.Errorf("%w: no . found in %q", errProtoFmt, bodyTypeName)
|
|
return TypeUnknown, msgType, err
|
|
}
|
|
return Type(bodyTypeName[0:lastDot]), msgType, nil
|
|
}
|
|
|
|
// IdentifyOrUnknown wraps Identify to return TypeUnknown and/or
|
|
// MessageTypeUnknown in the case where either one cannot be determined due to
|
|
// an error.
|
|
func IdentifyOrUnknown(msg *protocolpb.Message) (Type, MessageType) {
|
|
pt, mt, _ := Identify(msg)
|
|
return pt, mt
|
|
}
|
|
|
|
func (cerr constErr) Error() string {
|
|
return string(cerr)
|
|
}
|