-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
811 additions
and
501 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package api | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
const APIVersionHeaderName = "X-Supabase-Api-Version" | ||
|
||
type APIVersion = time.Time | ||
|
||
var ( | ||
APIVersionInitial = time.Time{} | ||
APIVersion20240101 = time.Date(2024, time.January, 1, 0, 0, 0, 0, time.UTC) | ||
) | ||
|
||
func DetermineClosestAPIVersion(date string) (APIVersion, error) { | ||
if date == "" { | ||
return APIVersionInitial, nil | ||
} | ||
|
||
parsed, err := time.ParseInLocation("2006-01-02", date, time.UTC) | ||
if err != nil { | ||
return APIVersionInitial, err | ||
} | ||
|
||
if parsed.Compare(APIVersion20240101) >= 0 { | ||
return APIVersion20240101, nil | ||
} | ||
|
||
return APIVersionInitial, nil | ||
} | ||
|
||
func FormatAPIVersion(apiVersion APIVersion) string { | ||
return apiVersion.Format("2006-01-02") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package api | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDetermineClosestAPIVersion(t *testing.T) { | ||
version, err := DetermineClosestAPIVersion("") | ||
require.NoError(t, err) | ||
require.Equal(t, APIVersionInitial, version) | ||
|
||
version, err = DetermineClosestAPIVersion("Not a date") | ||
require.Error(t, err) | ||
require.Equal(t, APIVersionInitial, version) | ||
|
||
version, err = DetermineClosestAPIVersion("2023-12-31") | ||
require.NoError(t, err) | ||
require.Equal(t, APIVersionInitial, version) | ||
|
||
version, err = DetermineClosestAPIVersion("2024-01-01") | ||
require.NoError(t, err) | ||
require.Equal(t, APIVersion20240101, version) | ||
|
||
version, err = DetermineClosestAPIVersion("2024-01-02") | ||
require.NoError(t, err) | ||
require.Equal(t, APIVersion20240101, version) | ||
} |
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
Oops, something went wrong.