blob: ad05121f5895c6bae10e61944e76bfc75b31cffc [file] [log] [blame]
Scott Bakere7144bc2019-10-01 14:16:47 -07001/*
2 * Copyright 2019-present Open Networking Foundation
3
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7
8 * http://www.apache.org/licenses/LICENSE-2.0
9
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package afrouter
18
19import (
20 "github.com/opencord/voltha-go/common/log"
21 "regexp"
22)
23
24type methodDetails struct {
25 all string
26 pkg string
27 service string
28 method string
29}
30
31// The compiled regex to extract the package/service/method
32var mthdSlicer = regexp.MustCompile(`^/([a-zA-Z][a-zA-Z0-9]+)\.([a-zA-Z][a-zA-Z0-9]+)/([a-zA-Z][a-zA-Z0-9]+)`)
33
34func newMethodDetails(fullMethodName string) methodDetails {
35 // The full method name is structured as follows:
36 // <package name>.<service>/<method>
37 mthdSlice := mthdSlicer.FindStringSubmatch(fullMethodName)
38 if mthdSlice == nil {
39 log.Errorf("Faled to slice full method %s, result: %v", fullMethodName, mthdSlice)
40 } else {
41 log.Debugf("Sliced full method %s: %v", fullMethodName, mthdSlice)
42 }
43 return methodDetails{
44 all: mthdSlice[0],
45 pkg: mthdSlice[1],
46 service: mthdSlice[2],
47 method: mthdSlice[3],
48 }
49}