-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: make ID an interface (#143)
- Loading branch information
Showing
50 changed files
with
306 additions
and
322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,9 @@ | ||
package resource | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
) | ||
// ID uniquely identifies a Pug resource. | ||
type ID any | ||
|
||
var ( | ||
// nextID provides the next ID for each kind | ||
nextID map[Kind]uint = make(map[Kind]uint) | ||
mu sync.Mutex | ||
) | ||
|
||
// ID is a unique identifier for a pug resource. | ||
type ID struct { | ||
Serial uint | ||
Kind Kind | ||
} | ||
|
||
func NewID(kind Kind) ID { | ||
mu.Lock() | ||
defer mu.Unlock() | ||
|
||
id := nextID[kind] | ||
nextID[kind]++ | ||
|
||
return ID{ | ||
Serial: id, | ||
Kind: kind, | ||
} | ||
} | ||
|
||
func (id ID) String() string { | ||
return fmt.Sprintf("#%d", id.Serial) | ||
} | ||
|
||
// GetID allows ID to be accessed via an interface value. | ||
func (id ID) GetID() ID { | ||
return id | ||
} | ||
|
||
// GetKind allows Kind to be accessed via an interface value. | ||
func (id ID) GetKind() Kind { | ||
return id.Kind | ||
// Identifiable is a Pug resource with an identity. | ||
type Identifiable interface { | ||
GetID() ID | ||
} |
Oops, something went wrong.