-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
- Loading branch information
Vladimir Popov
committed
Dec 3, 2020
1 parent
199182c
commit 0f92803
Showing
11 changed files
with
332 additions
and
208 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Metadata helper | ||
|
||
Metadata helper is a [genny](https://github.com/cheekybits/genny) template to generate a helper class for the metadata | ||
usage. Temlate parameters are: | ||
* prefix - prefix for the metadata type and constructor; | ||
* valueType - stored type. | ||
Generated helpers can both be exported (**P**refix) and unexported (**p**refix). | ||
|
||
gen.go: | ||
```go | ||
package connect | ||
|
||
//go:generate genny -in=../../utils/metadata/helper/meta_data.template.go -out=client_meta_data.gen.go -pkg=connect gen "prefix=client valueType=networkservice.NetworkServiceClient" | ||
``` | ||
client_meta_data.gen.go: | ||
```go | ||
// This file was automatically generated by genny. | ||
// Any changes will be lost if this file is regenerated. | ||
// see https://github.com/cheekybits/genny | ||
|
||
package connect | ||
|
||
import ( | ||
"context" | ||
"sync" | ||
|
||
"github.com/networkservicemesh/api/pkg/api/networkservice" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" | ||
) | ||
|
||
type _ClientKeyType struct{} | ||
|
||
type clientMetadataHelper struct { | ||
m *sync.Map | ||
} | ||
|
||
func clientMetadata(ctx context.Context, isClient bool) *clientMetadataHelper { | ||
return &clientMetadataHelper{ | ||
m: metadata.Map(ctx, isClient), | ||
} | ||
} | ||
|
||
func (h *clientMetadataHelper) Store(value networkservice.NetworkServiceClient) { | ||
h.m.Store(_ClientKeyType{}, value) | ||
} | ||
|
||
func (h *clientMetadataHelper) LoadOrStore(value networkservice.NetworkServiceClient) (networkservice.NetworkServiceClient, bool) { | ||
raw, ok := h.m.LoadOrStore(_ClientKeyType{}, value) | ||
return raw.(networkservice.NetworkServiceClient), ok | ||
} | ||
|
||
func (h *clientMetadataHelper) Load() (networkservice.NetworkServiceClient, bool) { | ||
if raw, ok := h.m.Load(_ClientKeyType{}); ok { | ||
return raw.(networkservice.NetworkServiceClient), true | ||
} | ||
return func() (v networkservice.NetworkServiceClient) { return }(), false | ||
} | ||
|
||
func (h *clientMetadataHelper) LoadAndDelete() (networkservice.NetworkServiceClient, bool) { | ||
if raw, ok := h.m.LoadAndDelete(_ClientKeyType{}); ok { | ||
return raw.(networkservice.NetworkServiceClient), true | ||
} | ||
return func() (v networkservice.NetworkServiceClient) { return }(), false | ||
} | ||
|
||
func (h *clientMetadataHelper) Delete() { | ||
h.m.Delete(_ClientKeyType{}) | ||
} | ||
``` |
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,18 @@ | ||
// Copyright (c) 2020 Doc.ai and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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 helper provides template for generating metadata helpers. | ||
package helper |
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,19 @@ | ||
// Copyright (c) 2020 Doc.ai and/or its affiliates. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// 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 helper | ||
|
||
//go:generate genny -in=meta_data.template.go -out=int_meta_data.gen.go gen "prefix=Int valueType=int" |
Oops, something went wrong.