Compare commits
	
		
			2 Commits 
		
	
	
		
			3d069e6921
			...
			a3b2417013
		
	
	| Author | SHA1 | Date | 
|---|---|---|
| 
							
							
								
									
								
								 | 
						a3b2417013 | |
| 
							
							
								
									
								
								 | 
						d8b3dc7b15 | 
| 
						 | 
					@ -0,0 +1,78 @@
 | 
				
			||||||
 | 
					package account_id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"sourcecode.social/reiver/go-mstdn"
 | 
				
			||||||
 | 
						"sourcecode.social/reiver/go-mstdn/ent"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var _ http.Handler = Handler{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const Path string = "/api/v1/accounts/{account_id}"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Handler struct {
 | 
				
			||||||
 | 
						LoaderFunc LoaderFunc
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (Handler) Path() string {
 | 
				
			||||||
 | 
						return Path
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (receiver Handler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
 | 
				
			||||||
 | 
						if nil == resp {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if nil == req {
 | 
				
			||||||
 | 
							mstdn.InternalServerError(resp)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if http.MethodGet != req.Method {
 | 
				
			||||||
 | 
							mstdn.MethodNotAllowed(resp)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fn := receiver.LoaderFunc
 | 
				
			||||||
 | 
						if nil == fn {
 | 
				
			||||||
 | 
							mstdn.InternalServerError(resp)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var accountid string
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							const key string = "accountid"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							url := req.URL
 | 
				
			||||||
 | 
							if nil == url {
 | 
				
			||||||
 | 
								mstdn.InternalServerError(resp)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							query := url.Query()
 | 
				
			||||||
 | 
							if nil == query {
 | 
				
			||||||
 | 
								mstdn.InternalServerError(resp)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if !query.Has(key) {
 | 
				
			||||||
 | 
								mstdn.BadRequest(resp)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							accountid = query.Get("accountid")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var account ent.Account
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err := fn(&account, accountid)
 | 
				
			||||||
 | 
							if nil != err {
 | 
				
			||||||
 | 
								mstdn.Error(resp, err.ErrHTTP())
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mstdn.OK(resp, account)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					package account_id
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"sourcecode.social/reiver/go-mstdn/api/v1"
 | 
				
			||||||
 | 
						"sourcecode.social/reiver/go-mstdn/ent"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type LoaderFunc func(account *ent.Account, accountid string) v1.Error
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,78 @@
 | 
				
			||||||
 | 
					package lookup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"net/http"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"sourcecode.social/reiver/go-mstdn"
 | 
				
			||||||
 | 
						"sourcecode.social/reiver/go-mstdn/ent"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var _ http.Handler = Handler{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const Path string = "/api/v1/accounts/lookup"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type Handler struct {
 | 
				
			||||||
 | 
						LoaderFunc LoaderFunc
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (Handler) Path() string {
 | 
				
			||||||
 | 
						return Path
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (receiver Handler) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
 | 
				
			||||||
 | 
						if nil == resp {
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if nil == req {
 | 
				
			||||||
 | 
							mstdn.InternalServerError(resp)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if http.MethodGet != req.Method {
 | 
				
			||||||
 | 
							mstdn.MethodNotAllowed(resp)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fn := receiver.LoaderFunc
 | 
				
			||||||
 | 
						if nil == fn {
 | 
				
			||||||
 | 
							mstdn.InternalServerError(resp)
 | 
				
			||||||
 | 
							return
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var acct string
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							const key string = "acct"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							url := req.URL
 | 
				
			||||||
 | 
							if nil == url {
 | 
				
			||||||
 | 
								mstdn.InternalServerError(resp)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							query := url.Query()
 | 
				
			||||||
 | 
							if nil == query {
 | 
				
			||||||
 | 
								mstdn.InternalServerError(resp)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if !query.Has(key) {
 | 
				
			||||||
 | 
								mstdn.BadRequest(resp)
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							acct = query.Get("acct")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var account ent.Account
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							err := fn(&account, acct)
 | 
				
			||||||
 | 
							if nil != err {
 | 
				
			||||||
 | 
								mstdn.Error(resp, err.ErrHTTP())
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						mstdn.OK(resp, account)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,8 @@
 | 
				
			||||||
 | 
					package lookup
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"sourcecode.social/reiver/go-mstdn/api/v1"
 | 
				
			||||||
 | 
						"sourcecode.social/reiver/go-mstdn/ent"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type LoaderFunc func(account *ent.Account, acct string) v1.Error
 | 
				
			||||||
		Loading…
	
		Reference in New Issue