一、添加依赖库、由于go受到网络、需要配置一下
Go模块的全局代理,类似nodejs中的cnpm、npm的功能
二、生成二维码
package main
import qrcode "github.com/skip2/go-qrcode"
import "fmt"
func main() {
err := qrcode.WriteFile("http://www.baidu.com", qrcode.Medium, 500, "go-qrcode.png")
if err != nil {
fmt.Println("write error")
}
}
三、LollipopGo
全球服游戏服务器框架,目前协议支持websocket、http及RPC,采用状态同步。
参考:https://github.com/Golangltd/LollipopGo
四、pravega (Streams的开源分布式存储服务)
介绍:Pravega是实现Streams的开源分布式存储服务。Pravega为连续和无限制的数据提供了新的存储抽象-流。Pravega流是持久的,弹性的,仅附加的,无边界的字节序列,具有良好的性能和强的一致性。
开源地址:https://github.com/pravega/pravega
package io.pravega.common.util;
import java.util.HashMap;
import java.util.Map;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
public class CopyOnWriteHashMap<K, V> implements Map<K, V> {
private volatile Map<K, V> contents;
public CopyOnWriteHashMap() {
this.contents = new HashMap<>();
}
public CopyOnWriteHashMap(Map<K, V> map) {
this.contents = Collections.unmodifiableMap(map);
}
// Provide access to the inner map that this class is wrapping.
public Map<K, V> getInnerMap() {
return this.contents;
}
// End region.
// Methods mutating internal state.
@Override
public synchronized V put(K k, V v) {
Map<K, V> newMap = new HashMap<>(this.contents);
V result = newMap.put(k, v);
this.contents = Collections.unmodifiableMap(newMap);
return result;
}
@Override
public synchronized void putAll(Map<? extends K, ? extends V> entries) {
Map<K, V> newMap = new HashMap<>(this.contents);
newMap.putAll(entries);
this.contents = Collections.unmodifiableMap(newMap);
}
@Override
public synchronized V putIfAbsent(K k, V v) {
return (!containsKey(k)) ? put(k, v) : get(k);
}
@Override
public synchronized V remove(Object key) {
Map<K, V> newMap = new HashMap<>(this.contents);
V result = newMap.remove(key);
this.contents = Collections.unmodifiableMap(newMap);
return result;
}
@Override
public synchronized boolean remove(Object k, Object v) {
if (containsKey(k) && get(k).equals(v)) {
remove(k);
return true;
}
return false;
}
@Override
public synchronized boolean replace(K k, V original, V replacement) {
if (containsKey(k) && get(k).equals(original)) {
put(k, replacement);
return true;
}
return false;
}
@Override
public synchronized V replace(K k, V v) {
return (containsKey(k)) ? put(k, v) : null;
}
// End region
// Read-only methods.
@Override
public boolean containsKey(Object k) {
return contents.containsKey(k);
}
@Override
public boolean containsValue(Object v) {
return contents.containsValue(v);
}
@Override
public Set<java.util.Map.Entry<K, V>> entrySet() {
return contents.entrySet();
}
@Override
public V get(Object k) {
return contents.get(k);
}
@Override
public boolean isEmpty() {
return contents.isEmpty();
}
@Override
public Set<K> keySet() {
return contents.keySet();
}
@Override
public int size() {
return contents.size();
}
@Override
public Collection<V> values() {
return contents.values();
}
@Override
public synchronized void clear() {
this.contents = new HashMap<>();
}
// End region
}
package io.pravega.common.util;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
public interface AsyncMap<K, V> {
CompletableFuture<Void> put(K key, V value, Duration timeout);
CompletableFuture<V> get(K key, Duration timeout);
CompletableFuture<Void> remove(K key, Duration timeout);
}