// NewSemVer generates a new SemVer from a string. If the given string does
// not represent a valid SemVer, nil and an error are returned.
192203
func NewSemVer(s string) (*SemVer, error) {
	nsv, err := semver.NewVersion(s)
	if err != nil {
		return nil, ErrBadSemVer
	}
	v := SemVer(*nsv)
	if v.Empty() {
		return nil, ErrNoZeroSemVer
	}
	return &v, nil
}
589831
func NewServer(hostname string, recorder record.EventRecorder, listener Listener, httpServerFactory HTTPServerFactory) Server {
	if listener == nil {
		listener = stdNetListener{}
	}
	if httpServerFactory == nil {
		httpServerFactory = stdHTTPServerFactory{}
	}
	return &server{
		hostname:    hostname,
		recorder:    recorder,
		listener:    listener,
		httpFactory: httpServerFactory,
		services:    map[types.NamespacedName]*hcInstance{},
	}
}
503893
func NewServerCodec(conn io.ReadWriteCloser) rpc.ServerCodec {
	return NewCodec(true, true, conn)
}
643483
func newServerConn(conn net.Conn, listener *Listener) *Conn {
	c := &Conn{
		conn:     conn,
		listener: listener,
		closed:   sync2.NewAtomicBool(false),
	}
	if listener.connReadBufferSize > 0 {
		c.bufferedReader = bufio.NewReaderSize(conn, listener.connReadBufferSize)
	}
	return c
}
1044739
func semverify(version string) string {
	match := semverPattern.FindStringSubmatch(version)
	if match != nil && len(match) == 6 {
		// replace the last component of the semver (which is always 0 in our versioning scheme)
		// with the number of commits since the last tag
		return fmt.Sprintf("%v.%v.%v+%v", match[1], match[2], match[4], match[5])
	}
	return version
}
797699
func NewServer(t testing.TB, h http.Handler, client *http.Client) *Server {
	return newServer(t, httptest.NewServer(h), client)
}
329644
func NewServer(config *Config) (*Server, error) {
	c, err := tlsutil.NewConfigurator(config.ToTLSUtilConfig(), nil)
	if err != nil {
		return nil, err
	}
	return NewServerLogger(config, nil, new(token.Store), c)
}
1339047
func NewString(key, val string) *api.GenericResource {
	return &api.GenericResource{
		Resource: &api.GenericResource_NamedResourceSpec{
			NamedResourceSpec: &api.NamedGenericResource{
				Kind:  key,
				Value: val,
			},
		},
	}
}
461222
func NewServer(serverAddr, root string) (*Server, error) {
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   strings.Split(serverAddr, ","),
		DialTimeout: 5 * time.Second,
	})
	if err != nil {
		return nil, err
	}

	return &Server{
		cli:  cli,
		root: root,
	}, nil
}
1135139
func NewServer(addr string) (*Server, error) {
	if (Conf == Config{}) {
		InitConf("")
	}

	s := Server{neptulon: neptulon.NewServer(addr)}

	if err := s.SetDB(inmem.NewDB()); err != nil {
		return nil, err
	}
	if err := s.SetQueue(inmem.NewQueue(s.neptulon.SendRequest)); err != nil {
		return nil, err
	}

	s.neptulon.MiddlewareFunc(middleware.Logger)
	s.pubRouter = middleware.NewRouter()
	s.neptulon.Middleware(s.pubRouter)
	initPubRoutes(s.pubRouter, &s.db, Conf.App.JWTPass())

	//all communication below this point is authenticated
	s.neptulon.MiddlewareFunc(jwt.HMAC(Conf.App.JWTPass()))
	s.neptulon.Middleware(s.queue)
	s.privRouter = middleware.NewRouter()
	s.neptulon.Middleware(s.privRouter)
	initPrivRoutes(s.privRouter, &s.queue)
	// todo: r.Middleware(NotFoundHandler()) - 404-like handler, if any request reaches this point without being handled

	s.neptulon.DisconnHandler(func(c *neptulon.Conn) {
		// only handle this event for previously authenticated
		if id, ok := c.Session.GetOk("userid"); ok {
			s.queue.RemoveConn(id.(string))
		}
	})

	return &s, nil
}
1166448
func NewServer(store *store.MemoryStore, raft *raft.Node, securityConfig *ca.SecurityConfig, pg plugingetter.PluginGetter, dr *drivers.DriverProvider) *Server {
	return &Server{
		store:          store,
		dr:             dr,
		raft:           raft,
		securityConfig: securityConfig,
		pg:             pg,
	}
}
847784
func toSemVer(version string) string {
	// Remove the first non-digit and non-dot character as well as the ones
	// following it.
	// E.g., "1.8.19p1" -> "1.8.19".
	if i := strings.IndexFunc(version, func(c rune) bool {
		if (c < '0' || c > '9') && c != '.' {
			return true
		}
		return false
	}); i != -1 {
		version = version[:i]
	}

	// Remove the trailing dots if there's any, and then returns an empty
	// string if nothing left.
	version = strings.TrimRight(version, ".")
	if version == "" {
		return ""
	}

	numDots := strings.Count(version, ".")
	switch {
	case numDots < semVerDotsCount:
		// Add minor version and patch version.
		// E.g. "1.18" -> "1.18.0" and "481" -> "481.0.0".
		version += strings.Repeat(".0", semVerDotsCount-numDots)
	case numDots > semVerDotsCount:
		// Remove anything beyond the patch version
		// E.g. "2.0.10.4" -> "2.0.10".
		for numDots != semVerDotsCount {
			if i := strings.LastIndex(version, "."); i != -1 {
				version = version[:i]
				numDots--
			}
		}
	}

	// Remove leading zeros in major/minor/patch version.
	// E.g., "2.02"     -> "2.2"
	//       "8.0.0095" -> "8.0.95"
	var subs []string
	for _, s := range strings.Split(version, ".") {
		s := strings.TrimLeft(s, "0")
		if s == "" {
			s = "0"
		}
		subs = append(subs, s)
	}
	return strings.Join(subs, ".")
}
843188
func NewServer(archiver pkgarchive.Archiver, opts ServerOptions) Server {
	return newServer(archiver, opts)
}
318113
func NewServer(addrs map[string]string) (s *Server, err error) {
	s = &Server{
		Listeners: make(map[string]net.Listener),
		control:   make(SignalChan),
	}

	for label, addr := range addrs {
		var listener net.Listener
		listener, err = net.Listen("tcp", addr)
		if err != nil {
			s.closeListeners()
			s = nil
			return
		}
		s.Listeners[label] = listener
		addrs[label] = listener.Addr().String()
	}
	return
}
1331704
func NewServer(bindHost string, bindPort int, syslogishServer *syslogish.Server) (*Server, error) {
	return &Server{
		bindHost: bindHost,
		bindPort: bindPort,
		handler:  &requestHandler{syslogishServer: syslogishServer},
	}, nil
}
208401
func NewServer(kind, name, addr, namespace string) *services.ServerV2 {
	return &services.ServerV2{
		Kind:    kind,
		Version: services.V2,
		Metadata: services.Metadata{
			Name:      name,
			Namespace: namespace,
		},
		Spec: services.ServerSpecV2{
			Addr:       addr,
			PublicAddr: addr,
		},
	}
}
490057
func NewServer(name string, s func(...server.Option) server.Server) Option {
	return func(o *Options) {
		o.Servers[name] = s
	}
}