Exemple #1
0
// Merge Intervals results
func (intervals *Intervals) Merge() {
	merged := make([]Interval, 0)

	for _, value := range intervals.List {
		// Markers
		intervalExists := false
		atInterval := 0

		// Check that Interval already exists in merged
		for mIndex, mValue := range merged {
			compareStart := strings.Compare(value.Start, mValue.Start)
			compareEnd := strings.Compare(value.End, mValue.End)

			if compareStart == 0 && compareEnd == 0 {
				intervalExists = true
				atInterval = mIndex
			}
		}

		// Add to existing value
		if intervalExists {
			merged[atInterval].Total += value.Total
			merged[atInterval].Unique += value.Unique
		} else {
			// Or append to merged
			merged = append(merged, value)
		}
	}

	// Set intervals.List to merged
	intervals.List = merged
}
Exemple #2
0
func command(args []string) {
	err := errors.New("No error")
	com := ""
	com_num := 0
	for _, arg := range args {
		fmt.Println(arg)
		if strings.Compare(com, "registe") == 0 {
			if com_num == 0 {
				fmt.Println("got one")
				persons[num].Name = arg
			} else {
				persons[num].Age, err = strconv.Atoi(arg)
				if err != nil {
					fmt.Println("Error: ", err)
				}
				num = num + 1
				com = "no"
			}
		}
		if strings.Compare(com, "list") == 0 {
			fmt.Println("Go another one")
			fmt.Println("num: ", num)
			for i := 0; i < num; i++ {
				fmt.Println("Name: ", persons[i].Name, "\tAge: ", persons[i].Age)
			}
		}
		if strings.Compare(com, "") == 0 {
			com = arg
		}
	}
}
Exemple #3
0
func Action(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
	r.ParseForm()
	action := mytypes.Action{}
	if 1 != len(r.Form) {
		fmt.Fprintf(w, "{\"status\":false}")
		return
	}
	for key, _ := range r.Form {
		err := json.Unmarshal([]byte(key), &action)
		if err != nil {
			fmt.Fprintf(w, "{\"status\":false}")
			return
		}

		// Action: start/stop
		for k, v := range action {
			if 0 == strings.Compare(k, "action") && (0 == strings.Compare(v, "start") || 0 == strings.Compare(v, "stop")) {
				// e.Set(k, v)
				log.Print("Key: ", k, ", Value: ", v)
				break
			} else {
				fmt.Fprintf(w, "{\"status\":false}")
				return
			}
		}
	} // for key
	fmt.Fprintf(w, "{\"status\":true")
}
Exemple #4
0
func (am AllMetadata) Validate() error {
	if am == nil || len(am) == 0 {
		return ErrValidatingData
	}

	// check some required fields
	var deviceType interface{}
	var imageID interface{}

	for k, v := range am {
		if v == nil {
			return ErrValidatingData
		}
		if strings.Compare(k, "deviceType") == 0 {
			deviceType = v
		}
		if strings.Compare(k, "imageId") == 0 {
			imageID = v
		}
	}
	if deviceType == nil || imageID == nil {
		return ErrValidatingData
	}
	return nil
}
Exemple #5
0
func PbrtTexture(name string, textype string, texname string, params *ParamSet) {
	VERIFY_WORLD("Texture")
	tp := CreateTextureParams(params, params, graphicsState.floatTextures, graphicsState.spectrumTextures)
	if strings.Compare(textype, "float") == 0 {
		// Create _float_ texture and store in _floatTextures_
		if graphicsState.floatTextures[name] != nil {
			Info("Texture \"%s\" being redefined", name)
		}
		WARN_IF_ANIMATED_TRANSFORM("Texture")
		ft := MakeFloatTexture(texname, curTransform.t[0], tp)
		if ft != nil {
			graphicsState.floatTextures[name] = ft
		}
	} else if strings.Compare(textype, "color") == 0 || strings.Compare(textype, "spectrum") == 0 {
		// Create _color_ texture and store in _spectrumTextures_
		if graphicsState.spectrumTextures[name] != nil {
			Info("Texture \"%s\" being redefined", name)
		}
		WARN_IF_ANIMATED_TRANSFORM("Texture")
		st := MakeSpectrumTexture(texname, curTransform.t[0], tp)
		if st != nil {
			graphicsState.spectrumTextures[name] = st
		}
	} else {
		Error("Texture type \"%s\" unknown.", textype)
	}
}
Exemple #6
0
func webhookHandler(w http.ResponseWriter, r *http.Request) {
	// Always reeturn text/plain OK with a 200 to obscure that this actually is.
	w.Header().Set("Content-Type", "text/plain")
	w.WriteHeader(http.StatusOK)
	fmt.Fprintf(w, "OK")

	log.Printf("Webhook Request: %s Path: %s RemoteAddr: %s UserAgent: %s\n", r.Method, r.URL.Path, r.RemoteAddr, r.UserAgent())
	if strings.Compare(r.Method, "POST") == 0 {
		header := r.Header
		contentType := header.Get("Content-Type")
		xGithubSignature := header.Get("X-Hub-Signature")
		if strings.Compare(contentType, "application/json") == 0 && xGithubSignature != "" {
			body, err := ioutil.ReadAll(r.Body)
			if err == nil && verifySignature([]byte(webhookSecret), xGithubSignature, body) == true {
				log.Printf("Webhook validated, running %q", webhookCommand)
				out, err := exec.Command(webhookCommand).Output()
				if err != nil {
					log.Printf("Webhook error: %s", err)
					return
				}
				log.Printf("Webhook out: %s", out)
				return
			}
		}
	}
	log.Printf("Webhook invalid request method.")
	return
}
Exemple #7
0
func TestGetMongoNormal(t *testing.T) {
	var data = `
  development:
    mongo:
      port: 27017
      host: mongo
      database: test
      credential:
        username: lunarc
        password: lunarc
  `
	mongo, err := GetMongo([]byte(data), "development")
	if err != nil {
		t.Fatalf("Non expected error %v", err)
	}
	if mongo.Port != 27017 {
		t.Fatalf("Must return a Mongo with Port 27017 not %v", mongo.Port)
	}
	if strings.Compare(mongo.Host, "mongo") != 0 {
		t.Fatalf("Must return a Mongo with Host mongo not %v", mongo.Host)
	}
	if strings.Compare(mongo.Database, "test") != 0 {
		t.Fatalf("Must return a Mongo with Database mongo not %v", mongo.Database)
	}
	if strings.Compare(mongo.Credential.Username, "lunarc") != 0 {
		t.Fatalf("Must return a Mongo with username credential lunarc not %v", mongo.Credential.Username)
	}
	if strings.Compare(mongo.Credential.Password, "lunarc") != 0 {
		t.Fatalf("Must return a Mongo with password credential lunarc not %v", mongo.Credential.Password)
	}
}
Exemple #8
0
func (rp *RootfsParser) ParseHeader(tr *tar.Reader, hdr *tar.Header, hPath string) error {
	relPath, err := filepath.Rel(hPath, hdr.Name)
	if err != nil {
		return err
	}

	switch {
	case strings.Compare(relPath, "files") == 0:
		if rp.updates == nil {
			rp.updates = map[string]UpdateFile{}
		}
		if err = parseFiles(tr, rp.updates); err != nil {
			return err
		}
	case strings.Compare(relPath, "type-info") == 0:
		// we can skip this one for now
	case strings.Compare(relPath, "meta-data") == 0:
		if _, err = io.Copy(&rp.metadata, tr); err != nil {
			return errors.Wrapf(err, "parser: error reading metadata")
		}
	case strings.HasPrefix(relPath, "checksums"):
		if err = processChecksums(tr, hdr.Name, rp.updates); err != nil {
			return err
		}
	case strings.HasPrefix(relPath, "signatures"):
		//TODO:
	case strings.HasPrefix(relPath, "scripts"):
		//TODO

	default:
		return errors.New("parser: unsupported element '" + relPath + "' in header")
	}
	return nil
}
Exemple #9
0
func testIt(rawStr string) {
	log.Printf("*** %s ***\n", rawStr)
	xiaBase64Encode := string(xiaBase64.Encode([]byte(rawStr)))
	stdBase64Encode := base64.StdEncoding.EncodeToString([]byte(rawStr))
	if strings.Compare(xiaBase64Encode, stdBase64Encode) != 0 {
		log.Println("xiaBase64Encode is wrong!")
		log.Printf("xia: %s , std: %s", xiaBase64Encode, stdBase64Encode)
		return
	}
	log.Println("xiaBase64Encode is right!")

	xiaBase64Decode, err := xiaBase64.Decode([]byte(xiaBase64Encode))
	if err != nil {
		log.Fatalln(err)
		return
	}
	stdBase64Decode, err := base64.StdEncoding.DecodeString(xiaBase64Encode)
	if err != nil {
		log.Fatalln(err)
	}
	if strings.Compare(string(xiaBase64Decode), string(stdBase64Decode)) != 0 {
		log.Println("xiaBase64Decode is wrong!")
		log.Printf("xia: %s , std: %s", xiaBase64Decode, stdBase64Decode)
		return
	}
	log.Println("xiaBase64Decode is right!")
}
Exemple #10
0
func CreateBilerpSpectrumTexture(tex2world *Transform, tp *TextureParams) *BilerpTextureSpectrum {
	// Initialize 2D texture mapping _map_ from _tp_
	var mapping TextureMapping2D
	maptype := tp.FindString("mapping", "uv")
	if strings.Compare(maptype, "uv") == 0 {
		su := tp.FindFloat("uscale", 1.0)
		sv := tp.FindFloat("vscale", 1.0)
		du := tp.FindFloat("udelta", 0.0)
		dv := tp.FindFloat("vdelta", 0.0)
		mapping = NewUVMapping2D(su, sv, du, dv)
	} else if strings.Compare(maptype, "spherical") == 0 {
		mapping = NewSphericalMapping2D(InverseTransform(tex2world))
	} else if strings.Compare(maptype, "cylindrical") == 0 {
		mapping = NewCylindricalMapping2D(InverseTransform(tex2world))
	} else if strings.Compare(maptype, "planar") == 0 {
		mapping = NewPlanarMapping2D(tp.FindVector("v1", Vector{1, 0, 0}),
			tp.FindVector("v2", Vector{0, 1, 0}),
			tp.FindFloat("udelta", 0.0), tp.FindFloat("vdelta", 0.0))
	} else {
		Error("2D texture mapping \"%s\" unknown", maptype)
		mapping = NewUVMapping2D(1, 1, 0, 0)
	}
	return NewBilerpTextureSpectrum(mapping,
		tp.FindSpectrum("v00", *NewSpectrum1(0)), tp.FindSpectrum("v01", *NewSpectrum1(1)),
		tp.FindSpectrum("v10", *NewSpectrum1(0)), tp.FindSpectrum("v11", *NewSpectrum1(1)))
}
Exemple #11
0
func (rp *GenericParser) ParseHeader(tr *tar.Reader, hdr *tar.Header, hPath string) error {
	relPath, err := filepath.Rel(hPath, hdr.Name)
	if err != nil {
		return err
	}

	switch {
	case strings.Compare(relPath, "files") == 0:
		if rp.updates == nil {
			rp.updates = map[string]UpdateFile{}
		}
		if err = parseFiles(tr, rp.updates); err != nil {
			return err
		}
	case strings.Compare(relPath, "meta-data") == 0:
		if _, err = io.Copy(&rp.metadata, tr); err != nil {
			return errors.Wrapf(err, "parser: error reading metadata")
		}
	case strings.HasPrefix(relPath, "checksums"):
		if err = processChecksums(tr, hdr.Name, rp.updates); err != nil {
			return err
		}
	}
	return nil
}
Exemple #12
0
//NextPacket Get one packet from Decoder. At the end of file,
//get error io.EOF with nil field.
func (d *Decoder) NextPacket() (field *Field, err error) {
	var out []byte
	var startRecord = false

	for {
		line, _, err := d.bufioReader.ReadLine()
		if err == io.EOF {
			return field, err
		} else if err != nil {
			return field, err
		}

		if strings.Compare(string(line), "<packet>") == 0 {
			startRecord = true
		}

		if startRecord {
			out = append(out, line...)
			out = append(out, byte('\n'))

			if strings.Compare(string(line), "</packet>") == 0 {
				break
			}
		}
	}

	r := bytes.NewReader(out)
	field, err = d.LoadPacket(r)
	if err != nil {
		return field, err
	}

	return
}
Exemple #13
0
func Test_cache_get(t *testing.T) {
	test_name := "Test_cache_get"
	setup_test_dir_cache(test_name)

	// create a file, and read it via the cache

	test_filename := "test.txt"
	test_bytes := []byte("This is a test file.")
	test_type := "text/plain"

	f, _ := _mkfile(test_filename)
	f.Write(test_bytes)
	f.Close()

	cache_init(default_timeout_ms)
	content_map_init()
	i, err := cache_get(test_filename)
	if err != nil {
		t.Errorf("error getting %s from the cache\n", test_filename)
		t.Errorf("%v", err)
	}

	if strings.Compare(i.Path, test_filename) != 0 {
		t.Errorf("Path:  expected '%s' but got '%s'\n", test_filename, i.Path)
	}

	if strings.Compare(i.Type, test_type) != 0 {
		t.Errorf("Type:  expected '%s' but got '%s'\n", test_type, i.Type)
	}

	if !bytes.Equal(i.Data, test_bytes) {
		t.Errorf("Data:  i.Data does not match test_bytes\n")
	}
}
func TestFormatOutput(t *testing.T) {
	n := NewPomodoro()

	n.Active = true

	_, n.Start = FormatDate(2015, time.January, 1, 0, 0)
	SetPomodoroDuration(n)

	expected := []string{"active", "Jan 01 2015 at 00:00:01.000", "Jan 01 2015 at 00:25:01.000"}
	got := FormatOutput(n)

	for i := 0; i < len(got); i++ {
		if strings.Compare(expected[i], got[i]) != 0 {
			t.Fail()
			t.Log(strings.Compare(expected[i], got[i]))
		}
		t.Log("\nExpected:", expected[i], "\nReceived:", got[i])
	}

	// Dont test this anymore, since it's effectively useless
	if len(expected) != len(got) {
		t.Fail()
		t.Log("\n Expected:", len(expected), "but got:", len(got))
	}
}
Exemple #15
0
func quickSort(array []KeyValue, left int, right int) {
	if left >= right {
		return
	}
	tmp := array[left].Key
	tmp_value := array[left].Value
	low := left
	high := right
	for low < high {
		for strings.Compare(array[high].Key, tmp) >= 0 && low < high {
			high--
		}
		array[low].Key = array[high].Key
		array[low].Value = array[high].Value
		for strings.Compare(array[low].Key, tmp) <= 0 && low < high {
			low++
		}
		array[high].Key = array[low].Key
		array[high].Value = array[low].Value
	}
	array[low].Key = tmp
	array[low].Value = tmp_value
	quickSort(array, left, low-1)
	quickSort(array, low+1, right)
}
Exemple #16
0
// Object Creation Function Definitions
func MakeShape(name string, object2world, world2object *Transform,
	reverseOrientation bool, paramSet *ParamSet) Shape {
	var s Shape = nil

	if strings.Compare(name, "sphere") == 0 {
		s = CreateSphereShape(object2world, world2object, reverseOrientation, paramSet)
	} else if strings.Compare(name, "cylinder") == 0 {
		s = CreateCylinderShape(object2world, world2object, reverseOrientation, paramSet)
	} else if strings.Compare(name, "disk") == 0 {
		s = CreateDiskShape(object2world, world2object, reverseOrientation, paramSet)
	} else if strings.Compare(name, "cone") == 0 {
		s = CreateConeShape(object2world, world2object, reverseOrientation, paramSet)
	} else if strings.Compare(name, "paraboloid") == 0 {
		s = CreateParaboloidShape(object2world, world2object, reverseOrientation, paramSet)
	} else if strings.Compare(name, "hyperboloid") == 0 {
		s = CreateHyperboloidShape(object2world, world2object, reverseOrientation, paramSet)
	} else if strings.Compare(name, "trianglemesh") == 0 {
		s = CreateTriangleMeshShape(object2world, world2object, reverseOrientation, paramSet, graphicsState.floatTextures)
	} else if strings.Compare(name, "heightfield") == 0 {
		s = CreateHeightfieldShape(object2world, world2object, reverseOrientation, paramSet)
	} else if strings.Compare(name, "loopsubdiv") == 0 {
		s = CreateLoopSubdivShape(object2world, world2object, reverseOrientation, paramSet)
	} else if strings.Compare(name, "nurbs") == 0 {
		s = CreateNURBSShape(object2world, world2object, reverseOrientation, paramSet)
	} else {
		Warning("Shape \"%s\" unknown.", name)
	}
	return s
}
Exemple #17
0
func setNS(rrs []string, r *dns.Msg, qns string) (string, string) {
	if debug {
		log.Printf("RRS %v,DNS Message %v Qns %v\n", rrs, r.String(), qns)
	}

	var ns string
	typ := "A"

	if strings.Contains(rrs[4], rrs[0]) || strings.Compare(qns, root) == 0 || fool {
		for _, rr := range r.Extra {
			rrss := splitRR(rr)
			if strings.Compare(rrss[3], "AAAA") == 0 {
				continue
			}
			if strings.Compare(rrss[0], rrs[4]) == 0 {
				ns = rrss[4]
				typ = rrss[3]
				break
			}
		}
	} else {
		ns = rrs[4]
	}

	if strings.Compare(ns, "") == 0 {
		ns = rrs[4]
	}
	return ns, typ
}
Exemple #18
0
func TestFormatOutput(t *testing.T) {
	n := NewPomodoro()

	n.Active = true
	// Pass the string to the bit bucket operator (underscore) since we are not going to use it in the test
	_, n.Start = FormatDate(2015, time.January, 1, 0, 0)
	AddPomodoroDuration(n)

	expected := []string{"active", "Jan 01 2015 at 00:00:01", "Jan 01 2015 at 00:25:01"}
	got := FormatOutput(n)

	for i := 0; i < len(got); i++ {
		// INFO: godoc -http=":6060"
		// http://localhost:6060/ref/spec#Index_expressions
		if strings.Compare(expected[i], got[i]) != 0 {
			t.Fail()
			t.Log(strings.Compare(expected[i], got[i]))
		}
		t.Log("\nExpected:", expected[i], "\nReceived:", got[i])
	}

	if len(expected) != len(got) {
		t.Fail()
		t.Log("\n Expected:", len(expected), "but got:", len(got))
	}
}
func typeUnify() {
	var elem string
	var ok bool

	for i := 0; i < len(left); i++ {
		/* BOTH TYPEVAR */
		if isValidTypeVar(right[i]) {
			/* If they are the same, delete from environment */
			if strings.Compare(left[i], right[i]) == 0 {
				continue
			}

			/* Change it into decending order */
			if strings.Compare(left[i], right[i]) > 0 {
				typeTokenizer(right[i], left[i])
				continue
			}
		}
		/* Check Whether have self cycle */
		if containType(left[i], right[i]) {
			fmt.Printf("%s\n", "BOTTOM")
			os.Exit(1)
		}
		/* Check if it exists */
		elem, ok = m[left[i]]
		if ok == true {
			/* Unify right part */
			typeTokenizer(elem, right[i])
		} else {
			/* Add to MAP */
			m[left[i]] = right[i]
		}
	}
}
Exemple #20
0
func IsStringNumber(txt string, decsep string) (f float64, e error) {
	hasDes := false
	newtxt := "0"
	decPoint := 0
	//Printf("%v ", txt)
	for _, c := range txt {
		s := string(c)
		if strings.Compare(s, "0") >= 0 && strings.Compare(s, "9") <= 0 {
			newtxt += s
			if hasDes {
				decPoint += 1
			}
		} else if s == decsep {
			if !hasDes {
				newtxt += "."
				hasDes = true
			} else {
				e = errors.New("IsStringNumber: Multiple decimal separator found")
				return
			}
		} else {
			//Printfn("%v %v", txt, s)
			e = errors.New("IsStringNumber: Wrong character " + txt)
			return
		}
	}
	if strings.HasSuffix(newtxt, ".") {
		newtxt += "0"
	}
	//Printfn("%v",newtxt)
	f = ToFloat64(newtxt, decPoint, RoundingAuto)
	return
}
Exemple #21
0
func getNextCommand() int {
	//Prompt for next action
	sMode := ""
	sAction := ""

	for {
		fmt.Print("TFTP Client(-h for help):")
		n, err := fmt.Scanln(&ServerAddress, &sMode, &sAction, &fSource, &fdest)
		fmt.Println("Number of tokens", n)
		if err != nil {
			fmt.Println("Error occurred: ", err)
		}
		if strings.Compare(strings.ToLower(ServerAddress), "-h") == 0 {
			fmt.Println("Please enter Server Address transfermode(-i or -a) action(get or put) sourcefilename destinationfilename")
			fmt.Println("separate each value with a space in between")
			continue
		}
		if strings.Compare(strings.ToLower(ServerAddress), "quit") == 0 {
			return (-1)
		}
		if strings.Compare(strings.ToLower(ServerAddress), "stop") == 0 {
			return (-1)
		}
		if strings.Compare(sMode, "-i") == 0 {
			binarymode = true
		}
		if strings.Compare(strings.ToLower(sAction), "get") == 0 {
			ReadMode = true
		}
		return (0)
	}
}
Exemple #22
0
func (ths *ImageTagServer) serveApi(w http.ResponseWriter, r *http.Request) {
	defer r.Body.Close()

	log.Println("Servicing APi")

	action := r.URL.Query().Get(ACTION_PARAMETER)

	if strings.Compare(action, LIST_DIR_ACTION) == 0 {
		ths.go_list_dir(w, r)
		return
	}

	if strings.Compare(action, GET_THUMB_IMAGE_ACTION) == 0 {
		ths.go_thumb_image(w, r)
		return
	}

	if strings.Compare(action, GET_IMAGE_ACTION) == 0 {
		ths.go_get_image(w, r)
		return
	}

	if strings.Compare(action, GET_TAGS_ACTION) == 0 {
		ths.get_tags(w, r)
		return
	}

	if strings.Compare(action, ASSIGN_TAG_ACTION) == 0 {
		ths.assign_tag(w, r)
		return
	}

	if strings.Compare(action, GET_TAGS_FOR_IMAGE_ACTION) == 0 {
		ths.get_tags_for_image(w, r)
		return
	}

	if strings.Compare(action, REMOVE_TAG_FOR_IMAGE_ACTION) == 0 {
		ths.remove_tag_for_iamge(w, r)
		return
	}

	if strings.Compare(action, ADD_NEW_TAG_ACTION) == 0 {
		ths.add_tag(w, r)
		return
	}

	if strings.Compare(action, GET_IMG_WITH_TAGS_ACTION) == 0 {
		ths.get_images_with_tags(w, r)
		return
	}

	if strings.Compare(action, GET_TAG_AS_ZIP) == 0 {
		ths.get_tag_as_zip(w, r)
		return
	}

	http.Error(w, "Unsupported action "+action, http.StatusBadRequest)
}
Exemple #23
0
func IsAuthenticated(r *http.Request, localToken string) bool {
	incomingToken := r.Header.Get("x-auth-token")
	if strings.Compare(localToken, "") != 0 && strings.Compare(localToken, incomingToken) == 0 {
		return true
	} else {
		return false
	}
}
Exemple #24
0
func (as *AuthServer) Authorize(ar *AuthRequest) ([]string, error) {
	for i, a := range as.authorizers {
		result, err := a.Authorize(&ar.ai)
		glog.V(2).Infof("Authz %s %s -> %s, %s", a.Name(), ar.ai, result, err)
		if err != nil {
			//			if err == authz.NoMatch {
			//				continue
			//			}
			err = fmt.Errorf("authz #%d returned error: %s", i+1, err)
			glog.Errorf("%s: %s", ar, err)
			return nil, authz.NoMatch
		}
		//		return result, nil

		// Authorize the scope
		account := ar.ai.Account
		glog.V(2).Infof("Authorize : account %s", account)

		// admin has full acl
		if strings.Compare(account, "super") == 0 {
			if actionIsPull(ar.ai.Actions) && actionIsPush(ar.ai.Actions) && strings.Contains(ar.ai.Name, "/") {
				glog.V(2).Infof("%s only push to root", account)
				return result, authz.ScopeNoMatch
			}
		}

		glog.V(2).Infof("Authorize : scope %s", ar.ai.Name)
		// user can only pull public and self scope
		if actionIsPull(ar.ai.Actions) && !actionIsPush(ar.ai.Actions) {
			if strings.Contains(ar.ai.Name, "/") {
				requestAccount := strings.Split(ar.ai.Name, "/")[0]
				if strings.Compare(account, requestAccount) != 0 {
					glog.V(3).Infof("%s can't pull %s", account, requestAccount)
					return result, authz.ScopeNoMatch
				}
			}
		}

		// user only push to self scope
		if actionIsPull(ar.ai.Actions) && actionIsPush(ar.ai.Actions) {
			if !strings.Contains(ar.ai.Name, "/") {
				glog.V(3).Infof("%s can't push to root", account)
				return result, authz.ScopeNoMatch
			} else {
				requestAccount := strings.Split(ar.ai.Name, "/")[0]
				if strings.Compare(account, requestAccount) != 0 {
					glog.V(3).Infof("%s can't push to %s", account, requestAccount)
					return result, authz.ScopeNoMatch
				}
			}
		}

		return result, nil
	}
	// Deny by default.
	glog.Warningf("%s did not match any authz rule", ar.ai)
	return nil, nil
}
Exemple #25
0
func MakeAreaLight(name string, light2world *Transform, paramSet *ParamSet, shape Shape) AreaLight {
	var area AreaLight = nil
	if strings.Compare(name, "area") == 0 || strings.Compare(name, "diffuse") == 0 {
		area = CreateDiffuseAreaLight(light2world, paramSet, shape)
	} else {
		Warning("Area light \"%s\" unknown.", name)
	}
	return area
}
func isLetter(s string) bool {
	if strings.Compare(s, "A") >= 0 && strings.Compare(s, "Z") <= 0 {
		return true
	}

	if strings.Compare(s, "a") >= 0 && strings.Compare(s, "z") <= 0 {
		return true
	}
	return false
}
Exemple #27
0
func main() {
	s := "Hello world"
	s_equal := "Hello world"
	s_not := "world, Hello"

	// Simply iterate over string
	for _, c := range s {
		fmt.Printf("%c\n", c)
	}

	arr := []rune(s)

	for _, r := range arr {
		fmt.Printf("%d\n", r)
	}

	fmt.Printf("s := %s\n", s)
	fmt.Printf("s_equal := %s\n", s_equal)
	fmt.Printf("s_not := %s\n", s_not)

	//Compare returns an integer comparing two strings lexicographically.
	// The result will be 0 if a==b, -1 if a < b, and +1 if a > b
	fmt.Printf("equal: %d\n", strings.Compare(s, s_equal))
	fmt.Printf("not equal: %d\n", strings.Compare(s, s_not))

	//Contains reports whether substr is within s.
	fmt.Printf("check if \"world\" is substr of s: %v\n", strings.Contains(s, "world"))
	fmt.Printf("check in \"cat\" is substr of s: %v\n", strings.Contains(s, "cat"))

	// ContainsAny reports whether any Unicode code points in chars are within s.
	fmt.Printf("any of \"abcd\" in s: %v\n", strings.ContainsAny(s, "abcd"))
	fmt.Printf("any of \"mkt\" in s: %v\n", strings.ContainsAny(s, "mkt"))

	// ContainsRune reports whether the Unicode code point r is within s.
	fmt.Printf("find rune 72 is s: %v\n", strings.ContainsRune(s, 72))

	//ToLower
	fmt.Printf("lowercase: %s\n", strings.ToLower(s))

	//ToUpper
	fmt.Printf("uppercase: %s\n", strings.ToUpper(s))

	sentence := "Simple sentence with many words"

	words := strings.Split(sentence, " ")

	fmt.Printf("%v\n", words)

	//Split with many whitespaces : strings.Fields

	words = strings.Fields(sentence)

	fmt.Printf("%v\n", words)

}
Exemple #28
0
func (sf1 *serfFilter) Compare(sf2 serfFilter) bool {
	if strings.Compare(sf1.Status, sf2.Status) != 0 {
		return false
	}

	if strings.Compare(sf1.Name, sf2.Name) != 0 {
		return false
	}

	return reflect.DeepEqual(sf1.Tags, sf2.Tags)
}
Exemple #29
0
func (req *Request) GetFresh() bool {
	if method := req.GetMethod(); strings.Compare("GET", method) != 0 &&
		strings.Compare("HEAD", method) != 0 {
		return false
	}
	if status := req.App.GetStatus(); (status >= 200 && status < 300) || 304 == status {
		return false
		//TODO:move fresh from npm to GO
	}
	return false
}
Exemple #30
0
func MakeVolumeIntegrator(name string, paramSet *ParamSet) VolumeIntegrator {
	var vi VolumeIntegrator = nil
	if strings.Compare(name, "single") == 0 {
		vi = CreateSingleScatteringIntegrator(paramSet)
	} else if strings.Compare(name, "emission") == 0 {
		vi = CreateEmissionVolumeIntegrator(paramSet)
	} else {
		Warning("Volume integrator \"%s\" unknown.", name)
	}
	return vi
}