Beispiel #1
0
// Init read yaml config
func (sender *Sender) Init(senderSettings map[string]string, logger *logging.Logger) error {
	sender.SetLogger(logger)
	sender.From = senderSettings["mail_from"]
	sender.SMTPhost = senderSettings["mail_smtp_host"]
	sender.SMTPport = int(to.Int64(senderSettings["mail_smtp_port"]))
	sender.InsecureTLS = to.Bool(senderSettings["mail_insecure_tls"])
	sender.FrontURI = senderSettings["front_uri"]
	return nil
}
Beispiel #2
0
func NewImage(r *http.Request, config HandlerConfig, fileName string) (image *Image, err error) {
	maxDimension := 3064
	height := int(to.Float64(r.URL.Query().Get("h")))
	width := int(to.Float64(r.URL.Query().Get("w")))
	if height > maxDimension {
		height = maxDimension
	}
	if width > maxDimension {
		width = maxDimension
	}
	crop := true
	if r.URL.Query().Get("c") != "" {
		crop = to.Bool(r.URL.Query().Get("c"))
	}
	image = &Image{
		Path:            config.AWS.FilePath,
		Bucket:          config.AWS.BucketName,
		Height:          height,
		Crop:            crop,
		Width:           width,
		CacheTime:       604800, // cache time in seconds, set 0 to infinite and -1 for disabled
		CachePath:       config.CachePath,
		ErrorImage:      "",
		ErrorResizeCrop: true,
		OutputFormat:    vips.WEBP,
	}
	if config.CacheTime != nil {
		image.CacheTime = *config.CacheTime
	}
	image.isFormatSupported(r.URL.Query().Get("f"))
	acceptedTypes := allowedTypes
	if config.Allowed != nil && len(config.Allowed) > 0 {
		acceptedTypes = config.Allowed
	}
	for _, allowed := range acceptedTypes {
		if allowed == filepath.Ext(fileName) {
			image.FileName = filepath.FromSlash(fileName)
		}
	}
	if image.FileName == "" {
		err = errors.New("File name cannot be an empty string")
	}
	if image.Bucket == "" {
		err = errors.New("Bucket cannot be an empty string")
	}
	return image, err
}
Beispiel #3
0
func main() {
	var response = []sugar.Tuple{}

	names := getPlugins()

	for _, name := range names {
		file := name + PS + "package.yaml"
		pkg, err := yaml.Open(file)

		if err != nil {
			panic(err)
		}

		item := sugar.Tuple{}

		keys := []string{
			"name",
			"stable",
			"latest",
			"license",
			"url",
			"demo_url",
			"description",
			"author",
			"copyright",
			"packages",
		}

		item["pkg"] = name

		for _, key := range keys {
			item[key] = pkg.Get(key)
		}

		if to.Bool(pkg.Get("hidden")) == false {
			response = append(response, item)
		}

	}

	data, _ := json.Marshal(response)

	fmt.Printf("%s", string(data))
}
Beispiel #4
0
// Get detailed codes from a character's armory page.
func wowarmory(options map[string]interface{}) (TMorphItems, error) {
	u, err := neturl.Parse(to.String(options["url"]))
	if err != nil {
		return nil, merry.Wrap(err)
	}

	parts := strings.Split(u.Path, "/")
	loc := -1
	for x := 0; x < len(parts); x++ {
		if parts[x] == "character" {
			loc = x + 1
			break
		}
	}

	if loc == -1 {
		return nil, errors.New("Could not parse battle.net URL")
	}

	// FIXME: this isn't exactly correct, because you can be in the US and want
	// to get the tmorph codes of a person in EU/China. So we need to probably
	// have settings to where the user of TMorphGen is.
	hostParts := strings.Split(u.Host, ".")
	if hostParts[0] == "cn" {
	} else if len(hostParts) == 2 {
		u.Host = "us.api." + strings.Join(hostParts, ".")
	} else {
		u.Host = hostParts[0] + ".api." + strings.Join(hostParts[1:], ".")
	}

	u.Scheme = "https"
	u.Path = fmt.Sprintf("/wow/character/%s/%s", parts[loc], parts[loc+1])
	u.RawQuery = "fields=items,appearance&locale=en_US"

	resp, err := apicall(u)
	if err != nil {
		return nil, merry.Wrap(err)
	}

	data, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, merry.Wrap(err)
	}
	resp.Body.Close()

	var tmorphItems TMorphItems
	var datam map[string]interface{}

	err = json.Unmarshal(data, &datam)
	if err != nil {
		return nil, merry.Wrap(err)
	}

	// get all armor, weapons, and enchants
	items := Map(datam["items"])
	for k, v := range items {
		if v, ok := v.(map[string]interface{}); ok {
			if canDisplayName(k) {
				id := to.Int64(v["id"])
				tooltipParams := Map(v["tooltipParams"])
				if !to.Bool(options["notmog"]) {
					transmogItem := tooltipParams["transmogItem"]
					if transmogItem != nil {
						id = to.Int64(transmogItem)
					}
				}

				tmorphItems = append(tmorphItems, &TMorphItem{
					Type: "item",
					Args: []int{nameSlotMap[k], int(id)},
				})

				// get enchants off the weapons
				if k == "mainHand" || k == "offHand" {
					if tooltipParams["enchant"] != nil {
						which := 1
						if k == "offHand" {
							which = 2
						}

						tmorphItems = append(tmorphItems, &TMorphItem{
							Type: "enchant",
							Args: []int{which, int(to.Int64(tooltipParams["enchant"]))},
						})
					}
				}
			}
		}
	}

	// set offhand to 0 if there is none.
	// TODO: maybe there should be defaults?
	if items["offHand"] == nil {
		tmorphItems = append(tmorphItems, &TMorphItem{
			Type: "item",
			Args: []int{nameSlotMap["offHand"], 0},
		})
	}

	// appearance stuff
	appearance := Map(datam["appearance"])
	for k, v := range appearance {
		if typ, ok := appearanceMap[k]; ok {
			tmorphItems = append(tmorphItems, &TMorphItem{
				Type: typ,
				Args: []int{int(to.Int64(v))},
			})
		}
	}
	tmorphItems = append(tmorphItems, &TMorphItem{
		Type: "race",
		Args: []int{int(to.Int64(datam["race"]))},
	}, &TMorphItem{
		Type: "gender",
		Args: []int{int(to.Int64(datam["gender"]))},
	})

	return tmorphItems, nil
}