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.
()
| 920 | // regardless of storage configuration, since each instance is intended to |
| 921 | // have its own unique ID. |
| 922 | func 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 |
nothing calls this directly
no test coverage detected