Giter Club home page Giter Club logo

mgo's Introduction

mgo


https://github.com/globalsign/mgo

clientCertPEM, err := ioutil.ReadFile("harness/certs/client.pem")
clientCertPEM, err := ioutil.ReadFile("harness/certs/client.pem")
clientCert, err := tls.X509KeyPair(clientCertPEM, clientKeyPEM)
clientCert.Leaf, err := x509.ParseCertificate(clientCert.Certificate[0])
tlsConfig := &tls.Config{
  Certificates: []tls.Certificate{clientCert},
  InsecureSkipverify: true,
}

host := "localhost:40003"
session, err := DialWithInfo(&DialInfo{
  Addrs: []string{host},
  DialServer: func(addr *ServerAddr) (net.Conn, error) {
    return tls.Dial("tcp", host, tlsConfig)
  },
})
cred := &Credential{Certificate: tlsConfig.Certificates[0].Leaf}
if err := session.Login(cred); err !- nil {
  panic(err)
}

_ = err



url := "mongodb://localhost:40003"

tlsConfig := &tls.Config{
}

dialInfo, err := ParseURL(url)
dialInfo.DialServer = func(addr *ServerAddr) (net.Conn, error) {
  return tls.Dial("tcp", addr.String(), tlsConfig)
}

session, err := DialWithInfo(dialInfo)
if err != nil {
  panic(err)
}

session.Close()


url := "mongodb://localhost:40003?ssl=true"

session, err = Dial(url)
if err != nil {
  panic(err)
}

session.Close()


var doStuff = func(wg *sync.WaitGroup, session *Session) {
  defer wg.Done()
  
  conn := session.Copy()
  defer conn.Close()
  
  _, _ = conn.DB("").C("my_data").Count()
}

session, err := Dial("localhost:40003/my_database")
if err != nil {
  panic(err)
}

wg := &sync.WaitGroup{}
for i := 0; i < 10; i++ {
  wg.Add(1)
  go doStuff(wg, session)
}
wg.Wait()

session.Close()

mgo's People

Contributors

takagotch avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.