github.com/slspeek/camlistore_namedsearch@v0.0.0-20140519202248-ed6f70f7721a/cmd/camtool/camtool.go (about)

     1  /*
     2  Copyright 2013 The Camlistore Authors.
     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/http"
    22  
    23  	"camlistore.org/pkg/client"
    24  	"camlistore.org/pkg/cmdmain"
    25  )
    26  
    27  func main() {
    28  	cmdmain.Main()
    29  }
    30  
    31  const serverFlagHelp = "Format is is either a URL prefix (with optional path), a host[:port], a config file server alias, or blank to use the Camlistore client config's default server."
    32  
    33  // newClient returns a Camlistore client for the server.
    34  // The server may be:
    35  //   * blank, to use the default in the config file
    36  //   * an alias, to use that named alias in the config file
    37  //   * host:port
    38  //   * https?://host[:port][/path]
    39  func newClient(server string) *client.Client {
    40  	var cl *client.Client
    41  	if server == "" {
    42  		cl = client.NewOrFail()
    43  	} else {
    44  		cl = client.New(server)
    45  		if err := cl.SetupAuth(); err != nil {
    46  			log.Fatal("Could not setup auth for connecting to %v: %v", server, err)
    47  		}
    48  	}
    49  	cl.SetHTTPClient(&http.Client{
    50  		Transport: cl.TransportForConfig(nil),
    51  	})
    52  	return cl
    53  }