-
Notifications
You must be signed in to change notification settings - Fork 0
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
czyt
committed
Oct 9, 2024
1 parent
ccc4dd9
commit 4b6e9c9
Showing
6 changed files
with
434 additions
and
95 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,46 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"github.com/ServiceWeaver/weaver" | ||
) | ||
|
||
var _ subConfigureProvider = (*subConfigure)(nil) | ||
|
||
type subConfigureProvider interface { | ||
GetSubFilePaths(ctx context.Context, privateSubToken string) ([]string, error) | ||
GetUrlSubs(ctx context.Context, privateSubToken string) ([]string, int, error) | ||
} | ||
|
||
type subConfig struct { | ||
weaver.AutoMarshal | ||
PublicSubFilePaths []string `toml:"public_sub_file_paths"` | ||
PrivateSubFilePaths []string `toml:"private_sub_file_paths"` | ||
UrlSubFetchTimeoutSeconds int `toml:"url_sub_fetch_timeout_seconds"` | ||
PublicUrlSubs []string `toml:"public_url_subs"` | ||
PrivateUrlSubs []string `toml:"private_url_subs"` | ||
|
||
PrivateSubToken string `toml:"private_sub_token"` | ||
} | ||
|
||
type subConfigure struct { | ||
weaver.Implements[subConfigureProvider] | ||
weaver.WithConfig[subConfig] | ||
} | ||
|
||
func (s *subConfigure) GetSubFilePaths(ctx context.Context, privateSubToken string) ([]string, error) { | ||
config := s.Config() | ||
if privateSubToken != config.PrivateSubToken { | ||
return config.PublicSubFilePaths, nil | ||
} | ||
return append(config.PrivateSubFilePaths, config.PublicSubFilePaths...), nil | ||
} | ||
|
||
func (s *subConfigure) GetUrlSubs(ctx context.Context, privateSubToken string) ([]string, int, error) { | ||
config := s.Config() | ||
if privateSubToken != config.PrivateSubToken { | ||
s.Logger(ctx).Info("token check pass") | ||
return config.PublicUrlSubs, config.UrlSubFetchTimeoutSeconds, nil | ||
} | ||
return append(config.PrivateUrlSubs, config.PublicUrlSubs...), config.UrlSubFetchTimeoutSeconds, nil | ||
} |
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.