-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
3,958 additions
and
650 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,35 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"net" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/weiwei04/compass/pkg/services/compass" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
var ( | ||
grpcAddr = flag.String("listen", ":8910", "address:port to listen on") | ||
grpcAddr = flag.String("rpcAddr", ":8910", "address:port to listen on") | ||
restAddr = flag.String("httpAddr", ":8911", "address:port to listen on") | ||
//enableTracing = flag.Bool("trace", false, "enable rpc tracing") | ||
tillerAddr = flag.String("tiller", "127.0.0.1:44134", "tiller address, default: :44134") | ||
registryAddr = flag.String("registry", "http://helm-registry:8900", "registry address, default: http://helm-registry:8900") | ||
mock = flag.Bool("mock", false, "enable mock, default false") | ||
) | ||
|
||
var count int | ||
|
||
func main() { | ||
flag.Parse() | ||
runServer() | ||
} | ||
|
||
func runServer() { | ||
zapLogger, _ := zap.NewProduction() | ||
defer zapLogger.Sync() | ||
sugger := zapLogger.Sugar() | ||
|
||
config := compass.Config{ | ||
TillerAddr: *tillerAddr, | ||
RegistryAddr: *registryAddr, | ||
ListenAt: *grpcAddr, | ||
RPCAddr: *grpcAddr, | ||
RESTAddr: *restAddr, | ||
Mock: *mock, | ||
} | ||
sugger.Infof("tiller[%s] registry[%s] listen[%s]", | ||
config.TillerAddr, config.RegistryAddr, config.ListenAt) | ||
|
||
ctx := context.Background() | ||
ctx, cancel := context.WithCancel(ctx) | ||
defer cancel() | ||
|
||
grpcHandler, err := compass.NewGRPCHandler(ctx, config) | ||
if err != nil { | ||
return | ||
} | ||
|
||
restHandler, err := compass.NewRESTHandler(ctx, config) | ||
if err != nil { | ||
return | ||
} | ||
|
||
conn, err := net.Listen("tcp", fmt.Sprintf("%s", config.ListenAt)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
srv := http.Server{ | ||
Addr: config.ListenAt, | ||
Handler: func(grpcHandler compass.GRPCHandler, restHandler compass.RESTHandler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") { | ||
grpcHandler.ServeHTTP(w, r) | ||
} else { | ||
restHandler.ServeHTTP(w, r) | ||
} | ||
}) | ||
}(grpcHandler, restHandler), | ||
} | ||
|
||
srv.Serve(conn) | ||
srv := compass.NewServer(config) | ||
srv.Serve() | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package client | ||
|
||
import ( | ||
"fmt" | ||
"github.com/caicloud/helm-registry/pkg/errors" | ||
"net/http" | ||
) | ||
|
||
type HTTPCodedError interface { | ||
String() string | ||
Error() string | ||
Code() int | ||
Desc() string | ||
} | ||
|
||
type httpCodedError struct { | ||
code int | ||
desc string | ||
} | ||
|
||
var _ HTTPCodedError = &httpCodedError{} | ||
|
||
func errorFromResponse(resp *http.Response) error { | ||
return &httpCodedError{resp.StatusCode, resp.Status} | ||
} | ||
|
||
func errorFromHelmRegistry(err error) error { | ||
if e, ok := err.(*errors.Error); ok { | ||
return &httpCodedError{e.Code, e.Message} | ||
} | ||
return err | ||
} | ||
|
||
func (e *httpCodedError) Error() string { | ||
return fmt.Sprintf("Code:%q, Desc:%q", e.code, e.desc) | ||
} | ||
|
||
func (e *httpCodedError) String() string { | ||
return fmt.Sprintf("Code:%q, Desc:%q", e.code, e.desc) | ||
} | ||
|
||
func (e *httpCodedError) Code() int { | ||
return e.code | ||
} | ||
|
||
func (e *httpCodedError) Desc() string { | ||
return e.desc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.