MCPcopy
hub / github.com/caddyserver/caddy / InstanceID

Function InstanceID

caddy.go:922–941  ·  view source on GitHub ↗

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.

()

Source from the content-addressed store, hash-verified

920// regardless of storage configuration, since each instance is intended to
921// have its own unique ID.
922func InstanceID() (uuid.UUID, error) {
923 appDataDir := AppDataDir()
924 uuidFilePath := filepath.Join(appDataDir, "instance.uuid")
925 uuidFileBytes, err := os.ReadFile(uuidFilePath)
926 if errors.Is(err, fs.ErrNotExist) {
927 uuid, err := uuid.NewRandom()
928 if err != nil {
929 return uuid, err
930 }
931 err = os.MkdirAll(appDataDir, 0o700)
932 if err != nil {
933 return uuid, err
934 }
935 err = os.WriteFile(uuidFilePath, []byte(uuid.String()), 0o600)
936 return uuid, err
937 } else if err != nil {
938 return [16]byte{}, err
939 }
940 return uuid.ParseBytes(uuidFileBytes)
941}
942
943// CustomVersion is an optional string that overrides Caddy's
944// reported version. It can be helpful when downstream packagers

Callers

nothing calls this directly

Calls 3

AppDataDirFunction · 0.85
ReadFileMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected