feat: refactor go.mod.
This commit is contained in:
14
utils/files.go
Normal file
14
utils/files.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package utils
|
||||
|
||||
import "os"
|
||||
|
||||
func PathExists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return false
|
||||
}
|
||||
38
utils/service_info.go
Normal file
38
utils/service_info.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package utils
|
||||
|
||||
import "os"
|
||||
|
||||
type ServiceInfo struct {
|
||||
Name string
|
||||
Version string
|
||||
Id string
|
||||
Metadata map[string]string
|
||||
}
|
||||
|
||||
func NewServiceInfo(name, version, id string) *ServiceInfo {
|
||||
if id == "" {
|
||||
id, _ = os.Hostname()
|
||||
}
|
||||
return &ServiceInfo{
|
||||
Name: name,
|
||||
Version: version,
|
||||
Id: id,
|
||||
Metadata: map[string]string{},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServiceInfo) SetName(name string) {
|
||||
s.Name = name
|
||||
}
|
||||
|
||||
func (s *ServiceInfo) SetVersion(version string) {
|
||||
s.Version = version
|
||||
}
|
||||
|
||||
func (s *ServiceInfo) GetInstanceId() string {
|
||||
return s.Id + "." + s.Name
|
||||
}
|
||||
|
||||
func (s *ServiceInfo) SetMataData(k, v string) {
|
||||
s.Metadata[k] = v
|
||||
}
|
||||
Reference in New Issue
Block a user