@ -33,6 +33,7 @@ import (
"time"
"time"
"github.com/caddyserver/certmagic"
"github.com/caddyserver/certmagic"
"github.com/google/uuid"
"go.uber.org/zap"
"go.uber.org/zap"
)
)
@ -662,6 +663,26 @@ func ParseDuration(s string) (time.Duration, error) {
return time . ParseDuration ( s )
return time . ParseDuration ( s )
}
}
// InstanceID returns the UUID for this instance, and generates one if it
// does not already exist. The UUID is stored in the local data directory,
// regardless of storage configuration, since each instance is intended to
// have its own unique ID.
func InstanceID ( ) ( uuid . UUID , error ) {
uuidFilePath := filepath . Join ( AppDataDir ( ) , "instance.uuid" )
uuidFileBytes , err := os . ReadFile ( uuidFilePath )
if os . IsNotExist ( err ) {
uuid , err := uuid . NewRandom ( )
if err != nil {
return uuid , err
}
err = ioutil . WriteFile ( uuidFilePath , [ ] byte ( uuid . String ( ) ) , 0644 )
return uuid , err
} else if err != nil {
return [ 16 ] byte { } , err
}
return uuid . ParseBytes ( uuidFileBytes )
}
// GoModule returns the build info of this Caddy
// GoModule returns the build info of this Caddy
// build from debug.BuildInfo (requires Go modules).
// build from debug.BuildInfo (requires Go modules).
// If no version information is available, a non-nil
// If no version information is available, a non-nil