afebcd89 by xiemengjun

删除老的文件

1 parent 818a34dd
No preview for this file type
1 package beego
2
3 import {
4 "net"
5 "net/http"
6 "net/http/fcgi"
7 "log"
8 "strconv"
9 "./core"
10 }
11 type C struct {
12 core.Content
13 }
14
15 type M struct{
16 core.Model
17 }
18
19 type D struct{
20 core.Config
21 }
22
23 type U struct{
24 core.URL
25 }
26
27 type A struct{
28 core.Controller
29 }
30
31 type V struct{
32 core.View
33 }
34
35 type BeegoApp struct{
36 Port int
37 }
38
39 func (app *BeegoApp) BeeListen(port int) {
40 app.Port = port
41 err := http.ListenAndServe(":"+strconv.Itoa(app.Port), nil)
42 if err != nil {
43 log.Fatal("ListenAndServe: ", err)
44 }
45 }
46
47 func (app *BeegoApp) BeeListenFcgi(port int) {
48 app.Port = port
49 l, err := net.Listen("tcp", "127.0.0.1:"+strconv.Itoa(port))
50 if err != nil {
51 log.Fatal("ListenAndServe: ", err)
52 }
53 fcgi.Serve(l, app.Handler)
54 }
55
56 func Run() {
57 rootPath, _ := os.Getwd()
58 }
...\ No newline at end of file ...\ No newline at end of file
File mode changed
1 package beego
2
3 // Interface for controller types that handle requests
4 type Controller interface {
5
6 // When implemented, handles the request
7 HandleRequest(c *Context)
8 }
9
10 // The ControllerFunc type is an adapter to allow the use of
11 // ordinary functions as goweb handlers. If f is a function
12 // with the appropriate signature, ControllerFunc(f) is a
13 // Controller object that calls f.
14 type ControllerFunc func(*Context)
15
16 // HandleRequest calls f(c).
17 func (f ControllerFunc) HandleRequest(c *Context) {
18 f(c)
19 }
...\ No newline at end of file ...\ No newline at end of file
1 package beego
2
3 import (
4 "regexp"
5 "strings"
6 )
7
8 /*
9 Route
10 */
11
12 // Represents a single route mapping
13 type Route struct {
14 pattern string
15 parameterKeys ParameterKeyMap
16 extension string
17 Path string
18 Controller Controller
19 MatcherFuncs []RouteMatcherFunc
20 }
21
22 func (r *Route) String() string {
23 return "{Route:'" + r.Path + "'}"
24 }
25
26 // Makes a new route from the given path
27 func makeRouteFromPath(path string) *Route {
28
29 // get the path segments
30 segments := getPathSegments(path)
31 regexSegments := make([]string, len(segments))
32
33 // prepare the parameter key map
34 var paramKeys ParameterKeyMap = make(ParameterKeyMap)
35
36 var extension string
37
38 // pull out any dynamic segments
39 for index, _ := range segments {
40
41 if isDynamicSegment(segments[index]) {
42
43 // e.g. {id}
44
45 paramKeys[strings.Trim(segments[index], "{}")] = index
46 regexSegments[index] = ROUTE_REGEX_PLACEHOLDER
47
48 } else if isExtensionSegment(segments[index]) {
49
50 // e.g. .json
51 extension = segments[index]
52
53 // trim off the last space (we don't need it)
54 regexSegments = regexSegments[0 : len(regexSegments)-1]
55
56 } else {
57
58 // e.g. "groups"
59
60 regexSegments[index] = segments[index]
61
62 }
63
64 }
65
66 patternString := "/" + strings.Join(regexSegments, "/")
67
68 // return a new route
69 var route *Route = new(Route)
70 route.pattern = patternString
71 route.extension = extension
72 route.parameterKeys = paramKeys
73 route.Path = path
74 route.Controller = nil
75 return route
76
77 }
78
79 // Gets the parameter values for the route from the specified path
80 func (route *Route) getParameterValueMap(path string) ParameterValueMap {
81 return getParameterValueMap(route.parameterKeys, path)
82 }
83
84 // Checks whether a path matches a route or not
85 func (route *Route) DoesMatchPath(path string) bool {
86
87 match, error := regexp.MatchString(route.pattern, path)
88
89 if error == nil {
90 if match {
91
92 if len(route.extension) > 0 {
93
94 // make sure the extensions match too
95 return strings.HasSuffix(strings.ToLower(path), strings.ToLower(route.extension))
96
97 } else {
98 return match
99 }
100
101 } else {
102
103 return false
104
105 }
106
107 }
108
109 // error :-(
110 return false
111
112 }
113
114 // Checks whether the context for this request matches the route
115 func (route *Route) DoesMatchContext(c *Context) bool {
116
117 // by default, we match
118 var match bool = true
119
120 if len(route.MatcherFuncs) > 0 {
121
122 // there are some matcher functions, so don't automatically
123 // match by default - let the matchers decide
124 match = false
125
126 // loop through the matcher functions
127 for _, f := range route.MatcherFuncs {
128
129 // modify 'match' based on the result of the matcher function
130 switch f(c) {
131 case NoMatch:
132 match = false
133 case Match:
134 match = true
135 }
136
137 }
138
139 }
140
141 // return the result
142 return match
143
144 }
...\ No newline at end of file ...\ No newline at end of file
1 package helper
2
3 import (
4 "json"
5 "io/ioutil"
6 "log"
7 )
8
9 var config map[string]string
10
11 func ReadConfig(filename string) {
12 contents, err := ioutil.ReadFile(filename)
13 if err != nil {
14 log.Exitf("Impossible to read %s", filename, err)
15 }
16 data, err := json.Decode(string(contents))
17 if err != nil {
18 log.Exitf("Can't parse %s as JSON", filename, err)
19 }
20 config = map[string]string{ }
21 for key, value := range data.(map[string]interface{ }) {
22 config[key] = value.(string)
23 }
24 }
25
26 func GetConfig(key string) string {
27 return config[key];
28 }
...\ No newline at end of file ...\ No newline at end of file
1 package server
2
3 import (
4 "bufio"
5 "bytes"
6 "errors"
7 "io"
8 "log"
9 "net"
10 "net/url"
11 "runtime/debug"
12 "strconv"
13 "strings"
14 )
...\ No newline at end of file ...\ No newline at end of file
1 // Copyright 2011 Google Inc. All rights reserved.
2 // Use of this source code is governed by the Apache 2.0
3 // license that can be found in the LICENSE file.
4
5 package guestbook
6
7 import (
8 "../../beego"
9 )
10
11 func init() {
12 beego.C.loadconfig()
13 }
14
15 func main() {
16 app:=beego.App
17 app.Run()
18 }
...\ No newline at end of file ...\ No newline at end of file
1 application: blog
2 handlers:
3 - url: "/user"
4 handlefun:"user.Index"
5 - url: "/blog"
6 handlefun:"blog.Index"
...\ No newline at end of file ...\ No newline at end of file
1 package controller
2
3 import (
4 "github.com/astaxie/beego/beego"
5 "../model"
6 )
7
8 func UserIndex(w beego.A) {
9 userinfo :=model.User.getAll()
10 beego.V.Render(w,"users/index")
11 }
...\ No newline at end of file ...\ No newline at end of file
1 package model
2 import (
3 "./beego"
4 )
5
6 type Users struct {
7 username string
8 password string
9 beego.M
10 }
11
12 func NewUsers() (a *Users) {
13 return &Users{}
14 }
...\ No newline at end of file ...\ No newline at end of file
1 package helloworld
2
3 import (
4 "fmt"
5 "net/http"
6 )
7
8 func init() {
9 http.HandleFunc("/", handle)
10 }
11
12 func handle(w http.ResponseWriter, r *http.Request) {
13 fmt.Fprint(w, "<html><body>Hello, World! 세상아 안녕!</body></html>")
14 }
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!