2 * Copyright (C) 2017-2018 "IoT.bzh"
3 * Author Sebastien Douheret <sebastien@iot.bzh>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
24 "gerrit.automotivelinux.org/gerrit/src/xds/xds-server.git/lib/xsapiv1"
27 // NewBuilderConfig creates a new BuilderConfig instance
28 func NewBuilderConfig(stID string) (xsapiv1.BuilderConfig, error) {
29 // Do we really need it ? may be not accessible from client side
30 ip, err := getLocalIP()
32 return xsapiv1.BuilderConfig{}, err
35 b := xsapiv1.BuilderConfig{
36 IP: ip, // TODO currently not used
37 Port: "", // TODO currently not used
45 func getLocalIP() (string, error) {
46 addrs, err := net.InterfaceAddrs()
50 for _, address := range addrs {
51 // check the address type and if it is not a loopback the display it
52 if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
53 if ipnet.IP.To4() != nil {
54 return ipnet.IP.String(), nil
58 return "", errors.New("Cannot determined local IP")