About - Angel's Blog.

ing
 
 
软件开发,程序设计,前端设计
 

About

 

This blog is licenced under a Creative Commons Licence Creative Commons Licence

Hello, everyone!

package main

// import
import (
    "bytes"
    "fmt"
    "strconv"
)

// define const
const (
    BASE_NAME = "Angel's Blog." ;
    NEXT = "\n" ;
    DOT = "." ;
    ZERO = 0 ;
    ONE = 1 ;
)

// struct defined
type Human struct {
    Name, Gender, Address, Bio, Blogger, Tumblr, ShortBio, QQ, QQGroup, Email string ;
    Virgin bool ;
    Age int ;
    Hobby, ITools []string ;
}

// write-datas with line!
func writeln(buff *bytes.Buffer, datas string) {
    buff.WriteString(datas);
    buff.WriteString(NEXT);
}

// write more-datas with line!
func writef(buff *bytes.Buffer, templates string, datas ...string) {
    res := make([]interface {}, len(datas)) ;
    for i, v := range datas {
        res[i] = v;
    }
    buff.WriteString(fmt.Sprintf(templates, res...));
    buff.WriteString(NEXT);
}

// array to string
func toString(arr []string) string {
    localStr := new(bytes.Buffer);
    var iLen = len(arr);
    for index, value := range arr {
        localStr.WriteString(value);
        if (index < iLen - ONE) {
            localStr.WriteString(", ");
        }
    }
    if (localStr.Len() > ZERO) {
        localStr.WriteString(DOT);
    }
    return localStr.String();
}

// print
func print(msg string) {
    fmt.Println(msg);
}

// get bio author info
func (h Human) getInfo() string {
    infoStr := new(bytes.Buffer);
    writef(infoStr, "My name is %s, I’m %s years old, I come from %s.", h.Name, strconv.Itoa(h.Age), h.Address);
    writeln(infoStr, "My favourite color is white which makes people feel clear.");
    if (h.Hobby != nil) {
        writef(infoStr, "In my leisure time, I have cultivated a lot of hobbies: %s", toString(h.Hobby));
    }
    writeln(infoStr, "Besides that, I have a happy family-father, mother and I, they care me a lot and I love them very much.");
    writeln(infoStr, "I feel lucky to have such a family, this is my brief introduction of myself.");
    writeln(infoStr, "That’s all, thank you very much!");
    writef(infoStr, "Blog URL: %s\nBlog Short URL: %s\nQQ: %s\nQQGroup: %s\nEmail: %s", h.Bio, h.ShortBio, h.QQ, h.QQGroup, h.Email);
    if (h.ITools != nil) {
        writef(infoStr, "Geek Equipment: %s", toString(h.ITools));
    }
    return infoStr.String();
}

// interface defined
type PersonService interface {
    getInfo() string;
}

// main method
func main() {
    // create myself.
    _human := &Human {
        Name: "Angel",
        Gender: "Male",
        Address: "north-east of china",
        Bio: "http://www.0ee.com/",
        ShortBio: "http://j2.cc/",
        Blogger: "http://blog.q86.net/",
        Tumblr: "http://www.caiming.net/",
        QQ: "MTEyMzMxMjM=",
        QQGroup: "MA==",
        Email: "emhhaW5hbihhdClvdXRsb29rKGRvdCljb20=",
        Virgin: true,
        Age: ,
        Hobby: []string {"Especially reading book", "Surfing the internet", "Google", "Twitter"},
        ITools: []string {"Macbook Pro MD101(x2)", "TP-LINK TL-MR11U", "TP-LINK TL-WN821N", "Huawei ET188", "Huawei E180", "Huawei EC169", "ITouch 4", "IPad 4(Cellular)", "Huawei A199", "CubieBoard 1GB(ARM)", "CubieTruck 2GB", "Oculus Rift DK2", "Google Glass 2(x2, white and blue)", "Google Nexus 5", "Nike Plus+", "JawBone Up2", "Leap Motion"},
    };
    msg := PersonService.getInfo(_human);
    print(msg);
}

 



或者通过RSS 关注本站的更新 ^ O ^ 。” —  by  转载请注明:来自 Angel's Blog.
本文永久链接: http://www.0ee.com/about
 
  • QQ书签
  • Del.icio.us
  • 百度收藏
  • Google
  • 饭否
  • FriendFeed
 
本文的评论功能被关闭了.
 
 
  • 正在加载...