// Home handles the request and returns the user home
2635
func Home() echo.HandlerFunc {

	// swagger:route GET /me/home me post home getMeHome
	//
	// Shows the homepage of the current user, mixing projects and users posts
	//
	// You can personalize the request via query string parameters
	//
	//	Produces:
	//	- application/json
	//
	//	Security:
	//		oauth: profile:read
	//
	//	Responses:
	//		default: MeHome

	return func(c echo.Context) error {
		if !rest.IsGranted("messages:read", c) {
			return rest.InvalidScopeResponse("messages:read", c)
		}

		me := c.Get("me").(*nerdz.User)
		options := c.Get("postlistOptions").(*nerdz.PostlistOptions)
		posts := me.Home(*options)

		if posts == nil {
			errstr := "Unable to fetch home page for the specified user"
			c.JSON(http.StatusBadRequest, &rest.Response{
				HumanMessage: errstr,
				Message:      "me.Home error",
				Status:       http.StatusBadRequest,
				Success:      false,
			})
			return errors.New(errstr)
		}

		var postsAPI []*nerdz.PostTO
		for _, p := range *posts {
			postsAPI = append(postsAPI, p.GetTO(me))
		}

		return rest.SelectFields(postsAPI, c)
	}
}
124554
func InitJujuXDGDataHome() error {
	jujuXDGDataHome := osenv.JujuXDGDataHomeDir()
	if jujuXDGDataHome == "" {
		return errors.New("cannot determine juju data home, required environment variables are not set")
	}
	charmrepo.CacheDir = osenv.JujuXDGDataHomePath("charmcache")

	sshDir := osenv.JujuXDGDataHomePath("ssh")
	if err := ssh.LoadClientKeys(sshDir); err != nil {
		return errors.Annotate(err, "cannot load ssh client keys")
	}
	ssh.SetGoCryptoKnownHostsFile(filepath.Join(sshDir, "gocrypto_known_hosts"))

	return nil
}
409279
func (ch *CredHub) AuthURL() (string, error) {
	if ch.authURL != nil {
		return ch.authURL.String(), nil
	}

	info, err := ch.Info()

	if err != nil {
		return "", err
	}

	authURL := info.AuthServer.URL

	if authURL == "" {
		return "", errors.New("AuthURL not found")
	}

	return authURL, nil
}
389959
func Default(address ...string) (server *Server) {
	c := &Options{}
	for _, addr := range address {
		c.Entries = append(c.Entries, Entry{Address: addr})
	}
	return New(c)
}
500137
func (req *Request) Header(key, val string) *Request {
	if req.headers == nil {
		req.headers = make(map[string]string, 5)
	}

	req.headers[key] = val

	return req
}
106778
func (c *AppPackageDeleteCall) Header() http.Header {
	if c.header_ == nil {
		c.header_ = make(http.Header)
	}
	return c.header_
}
69787
func Homedir() string {
	if hd := os.Getenv("GOPASS_HOMEDIR"); hd != "" {
		return hd
	}
	hd, err := homedir.Dir()
	if err != nil {
		if debug {
			fmt.Printf("[DEBUG] Failed to get homedir: %s\n", err)
		}
		return ""
	}
	return hd
}
843258
func (user *User) Home(options PostlistOptions) *[]Message {
	var message Message
	query := Db().
		CTE(`WITH blist AS (SELECT "to" FROM blacklist WHERE "from" = ?)`, user.ID()). // WITH cte
		Table(message.TableName()).                                                    // select * from messages
		Where(`"from" NOT IN (SELECT * FROM blist) AND
		CASE type
		WHEN 1 THEN "to" NOT IN (SELECT * FROM blist)
		ELSE ( -- groups conditions
			TRUE IN (SELECT visible FROM groups g WHERE g.counter = "to")
			OR
			(? IN (
				SELECT "from" FROM groups_members gm WHERE gm."to" = "to"
				UNION ALL
				SELECT "from" FROM groups_owners go WHERE go."to" = "to")
			)
		)
		END`, user.ID()).
		Order("time DESC")

	options.Model = message
	query = postlistQueryBuilder(query, options, user) // handle following, followers, language, newer, older, between...
	var posts []Message
	query.Scan(&posts)
	return &posts
}
562580
func (s *Server) Address() (string, error) {
	s.serverLock.RLock()
	defer s.serverLock.RUnlock()
	return s.server.Addr()
}
422986
func (web *webAPIHandlers) Login(r *http.Request, args *LoginArgs, reply *LoginRep) error {
	token, err := authenticateWeb(args.Username, args.Password)
	if err != nil {
		return toJSONError(err)
	}

	reply.Token = token
	reply.UIVersion = browser.UIVersion
	return nil
}
991953
func Public(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, homepage)
}
969734
func (r *httpVPackResponse) Header(key string) string {
	return r.resp.Header.Get(key)
}
833297
func Header(req *http.Request, key, val string) {
	req.Header.Set(key, val)
}
50172
func (c *ResetCall) Header() http.Header {
	if c.header_ == nil {
		c.header_ = make(http.Header)
	}
	return c.header_
}
824407
func getHomeDir() string {
	switch runtime.GOOS {
	case teleport.LinuxOS:
		return os.Getenv(teleport.EnvHome)
	case teleport.DarwinOS:
		return os.Getenv(teleport.EnvHome)
	case teleport.WindowsOS:
		return os.Getenv(teleport.EnvUserProfile)
	}
	return ""
}
44488
func userHomeDir() string {
	if runtime.GOOS == "windows" {
		home := os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
		if home == "" {
			home = os.Getenv("USERPROFILE")
		}
		return home
	}
	return os.Getenv("HOME")
}
738142
func expandUser(path string, lookupEnv template.Mapping) string {
	if strings.HasPrefix(path, "~") {
		home, ok := lookupEnv("HOME")
		if !ok {
			logrus.Warn("cannot expand '~', because the environment lacks HOME")
			return path
		}
		return strings.Replace(path, "~", home, 1)
	}
	return path
}