本文整理汇总了Golang中github.com/attic-labs/noms/go/d.PanicIfTrue函数的典型用法代码示例。如果您正苦于以下问题:Golang PanicIfTrue函数的具体用法?Golang PanicIfTrue怎么用?Golang PanicIfTrue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PanicIfTrue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleRootPost
func handleRootPost(w http.ResponseWriter, req *http.Request, ps URLParams, cs chunks.ChunkStore) {
d.PanicIfTrue(req.Method != "POST", "Expected post method.")
params := req.URL.Query()
tokens := params["last"]
d.PanicIfTrue(len(tokens) != 1, `Expected "last" query param value`)
last := hash.Parse(tokens[0])
tokens = params["current"]
d.PanicIfTrue(len(tokens) != 1, `Expected "current" query param value`)
current := hash.Parse(tokens[0])
// Ensure that proposed new Root is present in cs
c := cs.Get(current)
d.PanicIfTrue(c.IsEmpty(), "Can't set Root to a non-present Chunk")
// Ensure that proposed new Root is a Map and, if it has anything in it, that it's <String, <RefCommit>>
v := types.DecodeValue(c, nil)
d.PanicIfTrue(v.Type().Kind() != types.MapKind, "Root of a Database must be a Map")
m := v.(types.Map)
if !m.Empty() && !isMapOfStringToRefOfCommit(m) {
panic(d.Wrap(fmt.Errorf("Root of a Database must be a Map<String, Ref<Commit>>, not %s", m.Type().Describe())))
}
if !cs.UpdateRoot(current, last) {
w.WriteHeader(http.StatusConflict)
return
}
}
示例2: checkChunksInCache
func (lvs *ValueStore) checkChunksInCache(v Value, readValues bool) Hints {
hints := map[hash.Hash]struct{}{}
for _, reachable := range v.Chunks() {
// First, check the type cache to see if reachable is already known to be valid.
targetHash := reachable.TargetHash()
entry := lvs.check(targetHash)
// If it's not already in the cache, attempt to read the value directly, which will put it and its chunks into the cache.
if entry == nil || !entry.Present() {
var reachableV Value
if readValues {
// TODO: log or report that we needed to ReadValue here BUG 1762
reachableV = lvs.ReadValue(targetHash)
entry = lvs.check(targetHash)
}
if reachableV == nil {
d.Chk.Fail("Attempted to write Value containing Ref to non-existent object.", "%s\n, contains ref %s, which points to a non-existent Value.", v.Hash(), reachable.TargetHash())
}
}
if hint := entry.Hint(); !hint.IsEmpty() {
hints[hint] = struct{}{}
}
targetType := getTargetType(reachable)
d.PanicIfTrue(!entry.Type().Equals(targetType), "Value to write contains ref %s, which points to a value of a different type: %+v != %+v", reachable.TargetHash(), entry.Type(), targetType)
}
return hints
}
示例3: StringToValue
// StringToValue takes a piece of data as a string and attempts to convert it to a types.Value of the appropriate types.NomsKind.
func StringToValue(s string, k types.NomsKind) (types.Value, error) {
switch k {
case types.NumberKind:
if s == "" {
return types.Number(float64(0)), nil
}
fval, err := strconv.ParseFloat(s, 64)
if err != nil {
return nil, fmt.Errorf("Could not parse '%s' into number (%s)", s, err)
}
return types.Number(fval), nil
case types.BoolKind:
// TODO: This should probably be configurable.
switch s {
case "true", "1", "y", "Y":
return types.Bool(true), nil
case "false", "0", "n", "N", "":
return types.Bool(false), nil
default:
return nil, fmt.Errorf("Could not parse '%s' into bool", s)
}
case types.StringKind:
return types.String(s), nil
default:
d.PanicIfTrue(true, "Invalid column type kind:", k)
}
panic("not reached")
}
示例4: handleRootGet
func handleRootGet(w http.ResponseWriter, req *http.Request, ps URLParams, rt chunks.ChunkStore) {
d.PanicIfTrue(req.Method != "GET", "Expected post method.")
rootRef := rt.Root()
fmt.Fprintf(w, "%v", rootRef.String())
w.Header().Add("content-type", "text/plain")
}
示例5: handleRootPost
func handleRootPost(w http.ResponseWriter, req *http.Request, ps URLParams, rt chunks.ChunkStore) {
d.PanicIfTrue(req.Method != "POST", "Expected post method.")
params := req.URL.Query()
tokens := params["last"]
d.PanicIfTrue(len(tokens) != 1, `Expected "last" query param value`)
last := hash.Parse(tokens[0])
tokens = params["current"]
d.PanicIfTrue(len(tokens) != 1, `Expected "current" query param value`)
current := hash.Parse(tokens[0])
if !rt.UpdateRoot(current, last) {
w.WriteHeader(http.StatusConflict)
return
}
}
示例6: StringsToKinds
// StringsToKinds looks up each element of strs in the StringToKind map and returns a slice of answers
func StringsToKinds(strs []string) KindSlice {
kinds := make(KindSlice, len(strs))
for i, str := range strs {
k, ok := StringToKind[str]
d.PanicIfTrue(!ok, "StringToKind[%s] failed", str)
kinds[i] = k
}
return kinds
}
示例7: extractHashes
func extractHashes(req *http.Request) hash.HashSlice {
err := req.ParseForm()
d.PanicIfError(err)
hashStrs := req.PostForm["ref"]
d.PanicIfTrue(len(hashStrs) <= 0, "PostForm is empty")
hashes := make(hash.HashSlice, len(hashStrs))
for idx, refStr := range hashStrs {
hashes[idx] = hash.Parse(refStr)
}
return hashes
}
示例8: sendWriteRequests
func (bhcs *httpBatchStore) sendWriteRequests(hashes hash.HashSet, hints types.Hints) {
if len(hashes) == 0 {
return
}
bhcs.rateLimit <- struct{}{}
go func() {
defer func() {
<-bhcs.rateLimit
bhcs.unwrittenPuts.Clear(hashes)
bhcs.requestWg.Add(-len(hashes))
}()
var res *http.Response
var err error
for tryAgain := true; tryAgain; {
chunkChan := make(chan *chunks.Chunk, 1024)
go func() {
bhcs.unwrittenPuts.ExtractChunks(hashes, chunkChan)
close(chunkChan)
}()
body := buildWriteValueRequest(chunkChan, hints)
url := *bhcs.host
url.Path = httprouter.CleanPath(bhcs.host.Path + constants.WriteValuePath)
// TODO: Make this accept snappy encoding
req := newRequest("POST", bhcs.auth, url.String(), body, http.Header{
"Accept-Encoding": {"gzip"},
"Content-Encoding": {"x-snappy-framed"},
"Content-Type": {"application/octet-stream"},
})
res, err = bhcs.httpClient.Do(req)
d.PanicIfError(err)
expectVersion(res)
defer closeResponse(res.Body)
if tryAgain = res.StatusCode == httpStatusTooManyRequests; tryAgain {
reader := res.Body
if strings.Contains(res.Header.Get("Content-Encoding"), "gzip") {
gr, err := gzip.NewReader(reader)
d.PanicIfError(err)
defer gr.Close()
reader = gr
}
/*hashes :=*/ deserializeHashes(reader)
// TODO: BUG 1259 Since the client must currently send all chunks in one batch, the only thing to do in response to backpressure is send EVERYTHING again. Once batching is again possible, this code should figure out how to resend the chunks indicated by hashes.
}
}
d.PanicIfTrue(http.StatusCreated != res.StatusCode, "Unexpected response: %s", formatErrorResponse(res))
}()
}
示例9: handleHasRefs
func handleHasRefs(w http.ResponseWriter, req *http.Request, ps URLParams, cs chunks.ChunkStore) {
d.PanicIfTrue(req.Method != "POST", "Expected post method.")
hashes := extractHashes(req)
w.Header().Add("Content-Type", "text/plain")
writer := respWriter(req, w)
defer writer.Close()
for _, h := range hashes {
fmt.Fprintf(writer, "%s %t\n", h, cs.Has(h))
}
}
示例10: main
func main() {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n %s path/to/staging/dir\n", os.Args[0], os.Args[0])
}
flag.Parse(true)
if flag.Arg(0) == "" {
flag.Usage()
os.Exit(1)
}
err := d.Try(func() {
stagingDir, err := filepath.Abs(flag.Arg(0))
d.PanicIfTrue(err != nil, "Path to staging directory (first arg) must be valid, not %s", flag.Arg(0))
d.PanicIfError(os.MkdirAll(stagingDir, 0755))
goPath := os.Getenv("GOPATH")
d.PanicIfTrue(goPath == "", "GOPATH must be set!")
workspace := os.Getenv("WORKSPACE")
if workspace == "" {
fmt.Printf("WORKSPACE not set in environment; using GOPATH (%s).\n", goPath)
workspace = goPath
}
pythonPath := filepath.Join(goPath, nomsCheckoutPath, "tools")
env := runner.Env{
"PYTHONPATH": pythonPath,
}
if !runner.Serial(os.Stdout, os.Stderr, env, ".", buildScript) {
os.Exit(1)
}
if !runner.Serial(os.Stdout, os.Stderr, env, ".", stageScript, stagingDir) {
os.Exit(1)
}
})
if err != nil {
log.Fatal(err)
}
}
示例11: handleGetRefs
func handleGetRefs(w http.ResponseWriter, req *http.Request, ps URLParams, cs chunks.ChunkStore) {
d.PanicIfTrue(req.Method != "POST", "Expected post method.")
hashes := extractHashes(req)
w.Header().Add("Content-Type", "application/octet-stream")
writer := respWriter(req, w)
defer writer.Close()
for _, h := range hashes {
c := cs.Get(h)
if !c.IsEmpty() {
chunks.Serialize(c, writer)
}
}
}
示例12: Enqueue
// Enequeue adds a Chunk to the queue of Chunks waiting to be Put into vbs' backing ChunkStore. The instance keeps an internal buffer of Chunks, spilling to the ChunkStore when the buffer is full. If an attempt to Put Chunks fails, this method returns the BackpressureError from the underlying ChunkStore.
func (vbs *ValidatingBatchingSink) Enqueue(c chunks.Chunk) chunks.BackpressureError {
h := c.Hash()
if vbs.vs.isPresent(h) {
return nil
}
v := DecodeFromBytes(c.Data(), vbs.vs, vbs.tc)
d.PanicIfTrue(getHash(v) != h, "Invalid hash found")
vbs.vs.ensureChunksInCache(v)
vbs.vs.set(h, hintedChunk{v.Type(), h})
vbs.batch[vbs.count] = c
vbs.count++
if vbs.count == batchSize {
return vbs.Flush()
}
return nil
}
示例13: newBackingStore
func newBackingStore(dir string, maxFileHandles int, dumpStats bool) *internalLevelDBStore {
d.PanicIfTrue(dir == "", "dir cannot be empty")
d.PanicIfError(os.MkdirAll(dir, 0700))
db, err := leveldb.OpenFile(dir, &opt.Options{
Compression: opt.NoCompression,
Filter: filter.NewBloomFilter(10), // 10 bits/key
OpenFilesCacheCapacity: maxFileHandles,
WriteBuffer: 1 << 24, // 16MiB,
})
d.Chk.NoError(err, "opening internalLevelDBStore in %s", dir)
return &internalLevelDBStore{
db: db,
mu: &sync.Mutex{},
concurrentWriteLimit: make(chan struct{}, maxFileHandles),
dumpStats: dumpStats,
}
}
示例14: requestRoot
func (bhcs *httpBatchStore) requestRoot(method string, current, last hash.Hash) *http.Response {
u := *bhcs.host
u.Path = httprouter.CleanPath(bhcs.host.Path + constants.RootPath)
if method == "POST" {
d.PanicIfTrue(current.IsEmpty(), "Unexpected empty value")
params := u.Query()
params.Add("last", last.String())
params.Add("current", current.String())
u.RawQuery = params.Encode()
}
req := newRequest(method, bhcs.auth, u.String(), nil, nil)
res, err := bhcs.httpClient.Do(req)
d.PanicIfError(err)
return res
}
示例15: Serial
// Serial serially runs all instances of filename found under dir, mapping stdout and stderr to each subprocess in the obvious way. env is overlaid on the environment of the current process. If args are provided, they're passed en masse to each subprocess.
func Serial(stdout, stderr io.Writer, env Env, dir, filename string, args ...string) bool {
success := true
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if os.IsNotExist(err) {
// Some programs like npm create temporary log files which confuse filepath.Walk.
return nil
}
d.PanicIfTrue(err != nil, "Failed directory traversal at %s", path)
if !info.IsDir() && filepath.Base(path) == filename {
scriptAndArgs := append([]string{filepath.Base(path)}, args...)
runErr := runEnvDir(stdout, stderr, env, filepath.Dir(path), "python", scriptAndArgs...)
if runErr != nil {
success = false
fmt.Fprintf(stderr, "Running %s failed with %v\n", path, runErr)
}
}
return nil
})
d.PanicIfError(err)
return success
}