1// Copyright 2020 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package bind 16 17//Server receives RPC requests 18type Server struct { 19 priv PathBinder 20} 21 22func NewServer(binder PathBinder) *Server { 23 var s Server 24 s.priv = binder 25 return &s 26} 27 28type BindReadOnlyArgs struct { 29 Source string 30 Destination string 31} 32 33type BindReadOnlyReply struct { 34 // Errors types cannot be passed as-is in RPC so they 35 // must be converted to plain strings. 36 // Details at https://github.com/golang/go/issues/23340 37 Err string 38} 39 40func (s Server) BindReadOnly(args *BindReadOnlyArgs, reply *BindReadOnlyReply) error { 41 if err := s.priv.BindReadOnly(args.Source, args.Destination); err != nil { 42 reply.Err = err.Error() 43 } 44 return nil 45} 46 47type BindReadWriteArgs struct { 48 Source string 49 Destination string 50} 51 52type BindReadWriteReply struct { 53 // Errors types cannot be passed as-is in RPC so they 54 // must be converted to plain strings. 55 // Details at https://github.com/golang/go/issues/23340 56 Err string 57} 58 59func (s Server) BindReadWrite(args *BindReadWriteArgs, reply *BindReadWriteReply) error { 60 if err := s.priv.BindReadWrite(args.Source, args.Destination); err != nil { 61 reply.Err = err.Error() 62 } 63 return nil 64} 65 66type UnbindArgs struct { 67 Destination string 68} 69 70type UnbindReply struct { 71 // Errors types cannot be passed as-is in RPC so they 72 // must be converted to plain strings. 73 // Details at https://github.com/golang/go/issues/23340 74 Err string 75} 76 77func (s Server) Unbind(args *UnbindArgs, reply *UnbindReply) error { 78 if err := s.priv.Unbind(args.Destination); err != nil { 79 reply.Err = err.Error() 80 } 81 return nil 82} 83 84type ListArgs struct { 85} 86 87type ListReply struct { 88 BindList []string 89 // Errors types cannot be passed as-is in RPC so they 90 // must be converted to plain strings. 91 // Details at https://github.com/golang/go/issues/23340 92 Err string 93} 94 95func (s Server) List(args *ListArgs, reply *ListReply) error { 96 bindList, err := s.priv.List() 97 if err != nil { 98 reply.Err = err.Error() 99 } 100 reply.BindList = bindList 101 return nil 102} 103