Debian Codegraph @

examples/auth-locker/server.go

raw symbols SCIP
1 /*
2 * Minio Cloud Storage, (C) 2016 Minio, Inc.
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
17 package main
18
19 import (
20 "log"
21 "net"
22 "net/http"
23 "net/rpc"
24 "strconv"
25 "sync"
26 )
27
28 func StartLockServer(port int) {
29 lockServer := &LockServer{
30 resourceLockMapMutex: sync.Mutex{},
31 resourceLockMap: make(map[string][]int),
32 sessionListMutex: sync.Mutex{},
33 sessionList: make(map[string]struct{}),
34 }
35
36 portString := strconv.Itoa(port)
37 rpcPath := serviceEndpointPrefix + portString
38
39 rpcServer := rpc.NewServer()
40 rpcServer.RegisterName("LockServer", lockServer)
41 rpcServer.HandleHTTP(rpcPath, rpcPath)
42
43 listener, err := net.Listen("tcp", ":"+portString)
44 if err == nil {
45 log.Println("LockServer listening at port", port, "under", rpcPath)
46 http.Serve(listener, nil)
47 // It never returns
48 }
49
50 log.Println("Unable to start LockServer on port", port, "under", rpcPath)
51 log.Fatal("error:", err)
52 }