-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Source interface to use SourceID and JobID types #1774
Conversation
089a702
to
18a0523
Compare
The previous implementation used int64 for both, which can be mixed up easily. Using distinct types adds a layer of type safety checked by the compiler.
18a0523
to
553df09
Compare
@@ -123,7 +123,7 @@ func (s *Source) InjectConnection(conn *sourcespb.Syslog) { | |||
} | |||
|
|||
// Init returns an initialized Syslog source. | |||
func (s *Source) Init(_ context.Context, name string, jobId, sourceId int64, verify bool, connection *anypb.Any, concurrency int) error { | |||
func (s *Source) Init(_ context.Context, name string, jobId sources.JobID, sourceId sources.SourceID, verify bool, connection *anypb.Any, concurrency int) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: any reason sometimes it's jobID
like in line 52 and sometimes it's jobId
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, just ambiguity in what "camel case" means. I asked Ahrav at one point and the official Google style guide recommends jobID
, so I tend to use that.
https://google.github.io/styleguide/go/decisions#initialisms
I'll make a followup PR to update the variable names, since this PR is just updating the types.
@@ -111,7 +111,7 @@ func (c *persistableCache) shouldPersist() (bool, string) { | |||
} | |||
|
|||
// Init returns an initialized GCS source. | |||
func (s *Source) Init(aCtx context.Context, name string, id int64, sourceID int64, verify bool, connection *anypb.Any, concurrency int) error { | |||
func (s *Source) Init(aCtx context.Context, name string, id sources.JobID, sourceID sources.SourceID, verify bool, connection *anypb.Any, concurrency int) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: same question as jobID - looks like sometimes we use sourceID
and sometimes it's sourceId
. should this be standardized or do we use them for different purposes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when you say the implementation of int64 can be mixed up easily, do you mean by humans - or is there some Go thing that can happen? and what kind of additional type safety do we get beyond when it's just int64?
(other than the question^ and nits looks solid)
Yeah, by humans. Making them distinct types will allow the compiler to catch accidentally using a job ID as a source ID or vice versa. func Foo(sourceID int64, jobID int64)
func Bar(sourceID SourceID, jobID JobID)
Foo(jobID, sourceID) // no problemo (jobID and sourceID are both int64)
Bar(jobID, sourceID) // problemo (jobID and sourceID are distinct types) |
Description:
The previous implementation used int64 for both, which can be mixed up easily. Using distinct types adds a layer of type safety checked by the compiler.
Checklist:
make test-community
)?make lint
this requires golangci-lint)?