Debian Codegraph @

examples/auth-locker/main.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 "strconv"
22
23 "github.com/minio/dsync"
24 )
25
26 const basePort = 50001
27
28 func main() {
29 // Start four lock servers.
30 for i := 0; i < 4; i++ {
31 go StartLockServer(basePort + i)
32 }
33
34 // Create four lock clients.
35 lockClients := make([]dsync.NetLocker, 4)
36 for i := 0; i < 4; i++ {
37 lockClients[i] = newReconnectRPCClient("localhost", serviceEndpointPrefix+strconv.Itoa(basePort+i))
38 }
39
40 // Initialize dsync and treat 0th index on lockClients as self node.
41 if err := dsync.Init(lockClients, 0); err != nil {
42 log.Fatal("Fail to initialize dsync.", err)
43 }
44
45 // Get new distributed RWMutex on resource "Music"
46 drwMutex := dsync.NewDRWMutex("Music")
47
48 // Lock "music" resource.
49 drwMutex.Lock()
50
51 // As we got writable lock on Music, do some crazy things.
52
53 // Unlock "Music" resource.
54 drwMutex.Unlock()
55 }