-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Implement direct controller for Spanner Database
- Loading branch information
1 parent
ccb46d9
commit e5f9886
Showing
8 changed files
with
442 additions
and
16 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,51 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package directbase | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/googleapis/gax-go/v2/apierror" | ||
"k8s.io/klog/v2" | ||
) | ||
|
||
func ValueOf[T any](p *T) T { | ||
var v T | ||
if p != nil { | ||
v = *p | ||
} | ||
return v | ||
} | ||
|
||
// HasHTTPCode returns true if the given error is an HTTP response with the given code. | ||
func HasHTTPCode(err error, code int) bool { | ||
if err == nil { | ||
return false | ||
} | ||
apiError := &apierror.APIError{} | ||
if errors.As(err, &apiError) { | ||
if apiError.HTTPCode() == code { | ||
return true | ||
} | ||
} else { | ||
klog.Warningf("unexpected error type %T", err) | ||
} | ||
return false | ||
} | ||
|
||
// IsNotFound returns true if the given error is an HTTP 404. | ||
func IsNotFound(err error) bool { | ||
return HasHTTPCode(err, 404) | ||
} |
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.